Flushing output on a buffered stream means transmitting all accumulated characters to the file. There are many circumstances when buffered output on a stream is flushed automatically:
When you try to do output and the output buffer is full.
When the stream is closed. See Closing Streams.
When the program terminates by calling exit
. See Normal Termination.
When a newline is written, if the stream is line buffered.
Whenever an input operation on any stream actually reads data from its file.
If you want to flush the buffered output at another time, call fflush
, which is declared in the header file `stdio.h'.
fflush
causes buffered output on all open output streams to be flushed.
This function returns EOF
if a write error occurs, or zero otherwise.
Compatibility Note: Some brain-damaged operating systems have been known to be so thoroughly fixated on line-oriented input and output that flushing a line buffered stream causes a newline to be written! Fortunately, this ``feature'' seems to be becoming less common. You do not need to worry about this in the GNU system.