fflush
raw OCR
Hushes a stream.
Defined in header <stdio.h>
Syntax
#include <stdio.h>
int fflush(FILE *stream);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ | ■ | ■ |
Remarks
If the given stream has buffered output, fflush writes the output for stream to the associated file.
The stream remains open after fflush has executed, fflush has no effect on an unbuffered stream.
Return value
fflush returns 0 on success. It returns EOF if any errors were detected.
See also
Example
include <string.h>
#include <stdio.h>
#include <conio.h>
#include <io.h>
void flush (FILE *stream);
int main (void)
{
FILE *stream;
char msg[] = "This is a test";
/* create a file */
stream = fopen ("DUMMY.FIL", "w");
/* write some data to the file */
fwrite(msg, strlen(msg), 1, stream);
clrscr 0;
printf ("Press any key to flush DUMMY.FIL:");
getchO ;
/* flush the data to DUMMY.FIL without closing it */
flush (stream);
printf ("\nFile was flushed, Press any key to quit:");
getchO ;
return 0;
}
void flush (FILE *stream) {
int duphandle;
/* flush the stream's internal buffer */
fflush (stream);
/* make a duplicate file handle */
duphandle = dup (fileno(stream));
/* close the duplicate handle to flush the DOS buffer */
close(duphandle);
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/stdio.h/fflush/
· short form /3.1/fflush/