codescracker


c

C fflush()



« Previous Function Next Function »


fflush()

If stream is associated with a file that is opened for writing, a call to fflush() function causes the contents of the output buffer to be physically written to the file. The file remains open.

fflush() Syntax

Following is the syntax of the fflush() function

#include<stdio.h>
int fflush(FILE *stream);

On success, it returns zero, otherwise EOF indicates that a write error has occurred.

All the buffers are automatically flushed at the normal termination of program or when they are full. Also, closing a file flushed its buffer.

fflush() Example

Following c code flushes the buffer after each write operation (Let's assume that fp is associated with an output file) :

for(i=0; i<MAX; i++)
{
	fwrite(buf, sizeof(some_type), 1, fp);
	fflush(fp);
}

« Previous Function Next Function »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test