Function fflush () in C
The int fflush function (FILE * stream) in Library C flushes the output buffer of a Stream.
Declare the function fflush () in C
Below is the declaration for fflush () function in C:
int fflush ( FILE * stream )
Parameters
stream - This is a pointer to a FILE object that identifies a Stream buffered.
Returns the value
This function returns a value of 0 if successful. If there is an error, the EOF is returned and the Error Indicator is set (feof example).
For example
The following C program illustrates the usage of the fflush () function in C:
#include #include int main () { char buff [ 1024 ]; memset ( buff , '' , sizeof ( buff )); fprintf ( stdout , "Chuan bi buffern" ); setvbuf ( stdout , buff , _IOFBF , 1024 ); fprintf ( stdout , "Hoc C co ban va nang cao tai QTM !!!n" ); fprintf ( stdout , "Ket qua nay se duoc demn" ); fflush ( stdout ); return ( 0 ); }
Compiling and running the above program will produce the following results. Here, the program still buffers the output into the buff until it encounters the first call to the fflush () function, then it starts buffering output.
According to Tutorialspoint
Previous lesson: ferror () function in C
Next lesson: Function fgetpos () in C
You should read it
May be interested
- The function fgetpos () in Cthe int fgetpos function (file * stream, fpos_t * pos) in the c library standardizes the position of the current file of stream and writes it to pos.
- Function fopen () in Cthe function file * fopen (const char * filename, const char * mode) in library c opens the file pointed to the filename parameter by using the given mode.
- The function fread () in Cfunction size_t fread (void * ptr, size_t size, size_t nmemb, file * stream) in standard c library reads data from the given stream into the pointed array, by ptr.
- Function freopen () in Cfunction file * freopen (const char * filename, const char * mode, file * stream) in library c attaches a new filename with the given stream and at the same time closes the old file in stream.
- Function fseek () in Cthe function int fseek (file * stream, long int offset, int whence) in standard c library sets the stream file location to the given offset. the offset parameter specifies the number of bytes to search from where the given location is.
- The function fsetpos () in Cthe function int fsetpos (file * stream, const fpos_t * pos) in library c sets the file location of the stream to the given location. the pos parameter is a location provided by the fgetpos function.