Hello there,
I am reading a book about C "The C programming language" and I am implementing an example code to count the input characters.
Code:
#include <stdio.h>
/* count characters in input; 1st version */
main()
{
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%ld\n", nc);
}
The problem is that I don't know how to terminate this program and get the result. I know that the value of EOF = -1, but giving -1 as the input the program takes it as another input and continues to prompt me for the next input.
Any idea how I can terminate this program??
Thanks in advance.