This is homework and I'm stuck, it compiles but gives me the wrong word count. Your help is appreciated as always, I'm sure it's something simple I'm over looking.
include <stdio.h>
int main(void)
{
char line[100];
int i;
int words = 0;
printf("\nType in word string with one space after each word.\n\n");
scanf("%i", &words);
This is homework and I'm stuck, it compiles but gives me the wrong word count. Your help is appreciated as always, I'm sure it's something simple I'm over looking.
include <stdio.h>
int main(void)
{
char line[100];
int i;
int words = 0;
printf("\nType in word string with one space after each word.\n\n");
scanf("%i", &words);
while(words == 0)
{
if(line[0] == '\0')
break;
else
{
words++;
for(i = 0; line[i] != '\0'; i++)
if(line[i] == ' ' || line[i] == '\t')
words++;
}
}
printf("Number of words = %i\n", words);
) / End main /