I'm going through K&R C at the moment and I'm trying out an example in which the program takes a stream of characters as an input, and then prints the number of characters there are in the stream.
This doesn't seem to produce any output as far as I can see:
main()
{
long nc;
nc = 0;
while (getchar() != EOF){
++nc;
}
printf("%1d\n", nc);
}
However this seems to work fine albeit, slightly differently from what I want:
main()
{
long nc;
nc = 0;
while (getchar() != EOF){
++nc;
printf("%1d\n", nc);
}
}
Any pointers would be much appreciated. Thanks in advance!
EDIT
I've attempted simulating an EOF using ctrlz but that doesn't appear to be working. I'm running this off the cmd line on Windows 7 if that makes any difference.