meaj-gnu-linux
meaj-gnu-linux

Reputation: 21

Can I ignore getting end-of-file in C?

I am trying to make a program that asks a user for input. I already know how to terminate the program after getting EOF.

if(feof(stdin)) exit(1);

Or,

while(!feof(stdin)) { ... }

By ignoring I mean that the program does nothing after catching EOF. Like signal handling:

signal(SIGTERM, no_op_function);

Upvotes: 0

Views: 338

Answers (1)

meaj-gnu-linux
meaj-gnu-linux

Reputation: 21

Ok, here's what worked for me:

clearerr(stdin);

Thanks to @JonathanLeffler for the answer.

Upvotes: 1

Related Questions