RAD Studio
ContentsIndex
PreviousUpNext
fflush

Header File 

stdio.h  

Category 

Input/output Routines 

Prototype 

int fflush(FILE *stream); 

Description 

Flushes a stream. 

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. 

Example  

#include <string.h>
#include <stdio.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);
   printf("Press ENTER to flush DUMMY.FIL:");
   getchar();
   /* flush the data to DUMMY.FIL without closing it */
   flush(stream);
   printf("\nFile was flushed, Press ENTER to quit:");
   getchar();
   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);
}

Portability

POSIX 
Win32 
ANSI C 
ANSI C++ 
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!