fflush c – fflush C Library Function

fflush c: The function int fflush(FILE *stream); causes the content of an output buffer to be written on a file. The stream remains open after a call to fflush function. If stream is a null pointer, then all such streams are flushed.

All buffers automatically gets flushed when program terminates or because of a call to fclose or when they become full.

Function prototype of fflush

int fflush(FILE *stream);
  • stream : A pointer to a FILE object which identifies a stream.

Return value of fflush

fflush(stdout) in c: This function returns zero value on success. If an error occurs, It returns EOF and the error indicator is set.

C program using fflush function

fflush C Library Function

#include <stdio.h>
#include <string.h>
 
int main(){
   char buffer[100];
 
   memset(buffer, '\0', sizeof(buffer));
   setvbuf(stdout, buffer, _IOFBF, 100);
 
   fputs("fflush C Standard library function\n", stdout);
   fflush(stdout);
  
   return(0);
}

Output

fflush C Standard library function