The following is my code, where I use fgetc
to get input from stdin
. (running the program from a UNIX shell)
What I don't understand is that, when I type some characters from the keyboard, and then I press ctrl + D
and then press ENTER
, the program does not stop. It seems to me that EOF
has already been transmitted to the program, why wouldn't it stop?
I also found that if I press ENTER
, then ctrl + D
, the program does stop, but why?
#include "stdio.h"
int main()
{
char ch;
int i;
for (i = 0; i < 200; i++)
{
ch = fgetc(stdin);
if (ch == EOF)
break;
}
return 0;
}