Question about word/cha/new line count

Question:Write a C-program that asks for text input from the keyboard. The output of this program gives the amount of characters, the amount of words and the amount of newlines that has been typed. Reading keys from the keyboard is possible by using the function getchar(). The reading of characters from the keyboard can be stopped when the shutdown-code ^D (CTRL + D) is entered.
^D has the ASCII-value 4. Use a while loop.

And my code is as following:

void main ()
{
int charLength = 0;
int wordCount = 0;
int newlineCount = 1;
char c=getchar();

while (c != EOF)
{ while (c != '\n')

{
while (c != ' ')
{
c=getchar();
charLength++;
}
wordCount++;
c=getchar();

}

newlineCount++;
c=getchar();

}

printf("Amount of characters is %d\n", charLength);
printf("Amount of words is %d\n", wordCount);
printf("Amount of new line is %d\n", newlineCount);

}

Any clue why this is not working?

Thanks.
Topic archived. No new replies allowed.