I have experience in C++ so admittedly this shouldn't be too hard for me to understand but I guess it is. Im learning C from K&R's "The C Programming Language". I am performing this example from Chapter 1 Page 18, the example at the bottom of the page.
#include <stdio.h>
int main(){
double nc;
for(nc = 0; getchar() != EOF; ++nc)
;
printf("%.0f \n", nc);
return 0;
}
I am redirecting input from the keyboard to instead be read from a text file (using the '<' when running a.out), and the text file has absolutely nothing in it, not even a newline character.
The program prints a 1. Shouldn't it be 0? Is there a character that is being read that isn't an EOF value? Or is the for loop executing its contents once, then increment by 1, then check the condition?
Thank you for the help!