Standard Library Functions in C

adplus-dvertising
fflush() Function
Previous Home Next

Description

The C library function, The fflush() function is used for clearing the buffer before closing the file. It flushes the currently available pending data of files. All the output units will be flushed, in case the parameter is NULL. It is useful when some set of writes has completed before, like responding to a request.

Declaration

Following is the declaration for fflush() function.

int fflush(FILE *stream)

Parameters

stream - If stream is a null pointer, fflush() shall perform this flushing action on all streams.

Return Value

The fflush() function returns the value 0 if it successfully deletes the buffer. It returns EOF if an error occurs.

Example

#include <stdio.h>
#include <unistd.h> // caveat
 
int main(int argc, const char *argv[]) {
    printf("Hello world");
    //fflush(stdout);
    sleep(3);
 
    return 0;
}

Output

Hello world
Previous Home Next