I use the C code below to read data input from a terminal. If the user enters EOF, for example. by pressing ^ C, stdin closes and subsequent attempts to read from it, for example. via getchar () or scanf (), will throw an exception.
Is there anything I can do in C to βrestoreβ my program, in the sense that if some user accidentally enters EOF, it will be ignored, so I can read from stdin again?
#include <stdio.h>
int main(void)
{
int res_getchar=getchar();
getchar();
return 0;
}
lee77 source
share