Possible Duplicate:
Why doesn’t getchar() recognise return as EOF in windows console?
I’m trying to print out the value in the variable ‘nc’ in the next program:
int main()
{
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%ld\n", nc);
}
Please tell me why is it not printing?
You don’t have brackets in your while loop (this is why not using brackets leads to error prone software). Therefore, the value is getting incremented, but not printing.
Try:
otherwise, your code is essentially doing: