HP C/iX Library Reference Manual (30026-90004)

148 Chapter5
HP C/iX Library Function Descriptions
fflush
fflush
Flushes an I/O buffer to a file.
Syntax
#include <stdio.h>
int fflush (FILE *
stream
);
Parameters
stream
A file pointer to an output stream.
Return Values
0 Success.
EOF An error occurred.
Description
The fflush function causes any information that was buffered by the stream pointed to by
the
stream
argument to be flushed out to the associated file. The fflush function returns
an EOF if the flush operation caused a write error. It returns a zero if there was no error.
The fclose and exit functions automatically perform fflush(). Therefore, there is often
no need to call fflush() explicitly before closing a file or terminating a program. However,
it might be necessary to manually fflush() a stream.
For example, data written to a terminal is line buffered by default. This means the system
waits for a newline character before writing the buffer onto the terminal screen. There are
times when you want whatever has been written so far to be written to the screen without
waiting for the newline character. In such situations, you must use fflush.
Another situation when explicit use of the fflush function is needed is when you have
written less than a full buffer of data to a file, and you want the contents of that file
processed by another function. Because less than a full buffer was written, the data is still
in the buffer; the file is still empty. Performing an fflush() causes the buffered data to be
written out to the file, enabling other functions or commands to utilize the file's contents.
See Also
fopen(), exit(), setbuf(), ANSI C 4.9.5.2, POSIX.1 8.1