#include <stdio.h>
/* count characters in input; 1st version */
main()
{
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%ld\n", nc);
}
After I save that code out to a file named 'characterCount.c' I run the gcc command line tool like so:
gcc characterCount.c
It compiles fine, no errors. I then run the executable generated by the compiler like so:
./a.out
The program waits for my input, so I type a few characters, hit enter, and nothing prints out. The program is expecting more input. Why is that?! Shouldn't the line of code with the printf get executed? I know this is minor, but I really want to understand why the code is not executing all the way through. Is there some special switch I have to turn on while compiling to make it work?
Can anybody help me understand what is going on here. I'm particularly interested in why the program keeps expecting more input after I enter a line of characters.
Thank you for your time and help! |