tags:

views:

75

answers:

2

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()?

+2  A: 

The standard has this to say about fflush (slightly paraphrased):

  • If the stream is an output stream, or an update stream in which the most recent operation was not input, the 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!

paxdiablo
A: 

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.

Gabriel