What is EOF in the C programming language?

On Linux systems and OS X, the character to input to cause an EOF is CtrlD. For Windows, it’s CtrlZ.

Depending on the operating system, this character will only work if it’s the first character on a line, i.e. the first character after an Enter. Since console input is often line-oriented, the system may also not recognize the EOF character until after you’ve followed it up with an Enter.

And yes, if that character is recognized as an EOF, then your program will never see the actual character. Instead, a C program will get a -1 from getchar().

Leave a Comment