I am working on a K & R book and I find code example on how to read characters from a text stream. I copied their code and tried to run it, but when you ask for characters at the command line, the loop does not exit and therefore will never print the character counter. Is there a mistake here, I will not catch?
#include <stdio.h>
main()
{
long nc;
nc = 0;
while(getchar() != EOF) {
++nc;
}
printf("%1d\n", nc);
}
source
share