What is EOF in the C programming language?

Viewed 194663

How do you get to see the last print? In other words what to put in for EOF? I checked the definitions and it says EOF is -1.

And if you enter Ctrl-D you won't see anything.

#include <stdio.h>

int main() {
 int c;
 while((c = getchar() != EOF)) {
  printf("%d\n", c);
 }
 printf("%d - at EOF\n", c);
}
10 Answers

to keep it simple: EOF is an integer type with value -1. Therefore, we must use an integer variable to test EOF.

Related