Possible Duplicates:
Using fflush(stdin)
I am not able to flush stdin.
As scanf() does not absorb the new line entered,isnt that a good idea to use fflush(stdin) each time i use scanf()?
Possible Duplicates:
Using fflush(stdin)
I am not able to flush stdin.
As scanf() does not absorb the new line entered,isnt that a good idea to use fflush(stdin) each time i use scanf()?
The standard has this to say about fflush
(slightly paraphrased):
fflush
function causes any unwritten data for that stream to be delivered to the host environment to be written to the file; otherwise, the behaviour is undefined.In other words, fflush
should have zero beneficial effect in this case and, in fact, since stdin
is an input stream (invoking undefined behaviour), it can theoretically do whatever it wants, up to and including destroying the universe.
Don't do it!
If it's a single threaded console program, I would guess something else is up. Sorry this isn't a better answer, but if you post your program and what happens vs. what you expect, I could take a look.