Can't read anything after sending EOF?

Viewed 64
#include <stdio.h>
int main()
{
    char c = getchar(); //EOF (ctrl + d )
    while( ( c = getchar() ) != '?' )
    {
        printf( "%d\n", c == EOF );//infinite loop printing 1
    }
}

What happens here?

It is as if EOF completely blocks reading anything after it?

1 Answers

You need to call clearerr on stdin to clear the EOF. Also, note that getchar returns an int and not a char because EOF does not fit in a char.

Related