What is Fflush Stdin?


Explanation of fflush() in C

The fflush() function causes the system to empty the buffer that is associated with the specified output stream, if possible. The stream remains open after the call. If stream is NULL, the system flushes all open streams.

Use alternative method for clearing keyboard input

You don’t need to flush stdin to get rid of whitespace, simply call scanf again and it will skip all the whitespace.

Clarification on fflush() for stdout

fflush() is typically used for output stream only. Its purpose is to clear (or flush) the output buffer and move the buffered data to console (in case of stdout) or disk (in case of file output stream). fflush(stdout) means write all of the buffered data to its destination – whatever stdout is.

Lascia un commento