fflush
Syntax
- int fflush(int filepointer)
Arguments
- filepointer
- A pointer to a file/stream previously opened with fopen.
Return
- Returns 0 if the file is flushed successfully, and EOF if it encounters any problems.
Description
- Writes all remaining data in the writing buffer of the specified filepointer to the associated file.
- The main use of this function is security; ensuring the data is stored in the file in order to protect against crashes. Use this function if your file format allows processing of the partial file.
Example
int IMG_FILE;
if (IMG_FILE = fopen("d:\\FM_image0.fmi", "wb")) {
// Write out the src pixels as raw data
for (z = 0; z < Z; ++z) {
for (y = 0; y < Y; ++y) {
for (x = 0; x < X; ++x) {
fputc(src(x, y, z), IMG_FILE);
}
}
fflush(IMG_FILE); // ensure complete channel is stored before next channel is written.
}
}
else
ErrorOk("Cannot write image file\nDrive is either full or write-protected!");
if (fclose(IMG_FILE))
ErrorOk("Cannot close image file!");
Also see
- flushall
Comments
- Everyone can add his comments about his experiences with this function here. Tips for using it are welcome, too.