Why does getchar() recognize EOF only in the beginning of a line?
问题 This example is from the K&R book #include<stdio.h> main() { long nc; nc = 0; while(getchar() != EOF) ++nc; printf("%ld\n", nc); } Could you explain me why it works that way. Thanks. ^Z^Z doesn't work either (unless it's in the beginning of a line) 回答1: Traditional UNIX interpretation of tty EOF character is to make blocking read return after reading whatever is buffered inside a cooked tty line buffer. In the start of a new line, it means read returning 0 (reading zero bytes), and