I'm writing a program that gets characters from the user using getchar
and counts them. It's supposed to stop when the user enters EOF, print out the char count and print done. The code:
char cur = 0;
int count = 0;
while((cur = getchar()) != EOF){
++count;
}
printf("\n%d", count);
printf("\ndone\n");
However the loop doesn't stop until the user enters 2 consecutive EOF. I tried to force the loop to stop by by manually checking if the char is EOF and breaking the loop but it doesn't seem to work.
How can I make it stop after just one EOF?