How to flush the stdin??
Why is it not working in the following code snippet?
#include
#include
#i
I believe fflush is only used with output streams.
You might try fpurge or __fpurge on Linux. Note that fpurge is nonstandard and not portable. It may not be available to you.
From a Linux fpurge man page: Usually it is a mistake to want to discard input buffers.
The most portable solution for flushing stdin would probably be something along the lines of the following:
int c;
while ((c = getchar()) != '\n' && c != EOF);