Hi there i need a program to count words, lines, characters.
I have the character and line count down but the word count is off
can some one please help.
printf("Please enter text:\n");
while((ch = getchar()) != EOF)
{
c ++;
if (ch == '\n')
line ++;
if (ch == ' ')
word ++;
}
printf("The given text contained %i words\n", word);
printf("The given text contained %i characters\n",c);
printf("The given text contained %i lines\n", line);
system("pause");
return 0;
}
Here is the output:
it should be 6 words but only displays 4 words
the character and line count is correct though,
Please enter text:
hi hi hi
hi hi hi
^Z
The given text contained 4 words
The given text contained 18 characters
The given text contained 2 lines
Press any key to continue . . .