Fflush

fflush is a C function belonging to the ANSI C standard library, and included in the file stdio.h. Its purpose is to deliver, to the host environment, unwritten data present in an output or update stream, or multiple streams, to be actually written to those streams' underlying file or device.
For its behavior to be well-defined on an update stream, the behavior of fflush is defined only if the most recent operation was not input.
Return value
The return value is an integer which means:
* 0 (zero) : function performed successfully in the stream.
* EOF : an error occurred and errno is set.
Note that each error number has a distinct meaning. The meaning can usually be revealed by checking errno.h; the strerror() function converts an error number to a descriptive text string.
Remarks
* The fflush function is usually used to prevent data loss by ensuring that the data is written to stream
* It should be used for output streams only; otherwise the behavior is undefined.
* Often fflush is used on the standard output stream because stdout is usually buffered and the output might not be prompted immediately.
* A call to fclose will flush the stream.
* A null argument did not have defined behavior in older implementations of the C library.
* It is a common, though incorrect practice to use fflush on the input stream, in order to clear any extraneous input left behind by a scanf function. This may not work in all compilers, and should generally be avoided.
 
< Prev   Next >