C 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

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);

C Online Test

« Previous Function Next Function »

Like/Share Us on Facebook 😋