[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
fflush

Empty a stream's buffer to its host environment.
Compatibility:
This function is compatible with the following targets:
Prototype:
#include <stdio.h>
int fflush(FILE *stream);
Parameters:
Parameters for this facility are:
Remarks:
The fflush() function empties stream's buffer to the file associated with stream. If the stream points to 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 behavior is undefined.
NOTE
The fflush() function should not be used after an input operation.
WARNING!
Using fflush() for input streams especially the standard input stream (stdin) is undefined and is not supported and will not flush the input buffer.
NOTE
On embedded/ RTOS systems this function only is implemented for stdin, stdout and stderr files.
Return:
The function fflush() returns EOF if a write error occurs, otherwise it returns zero.
See Also:
"setvbuf"
Example of fflush() usage:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *f;
int count;
// create a new file for output
if (( f = fopen("foofoo", "w")) == NULL) {
printf("Can't open file.\n");
exit(1);
}
for (count = 0; count < 100; count++) {
fprintf(f, "%5d\n", count);
if (count % 10)
fflush(f); // flush buffer every 10 numbers
}
fclose(f);
return 0;
}
[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.
Last updated: August 16, 2000