Latest web development tutorials

C library functions - fflush ()

C standard library - <stdio.h> C standard library - <stdio.h>

description

C library functionsint fflush (FILE * stream) Flush the stream stream output buffer.

statement

Here is the fflush () function's declaration.

int fflush(FILE *stream)

parameter

  • stream - This is a pointer to FILE pointer to an object, the object specifies a FILE stream buffer.

return value

If successful, the function returns a value of zero. If an error occurs, it returns EOF, and set the error identifier (ie, feof).

Examples

The following example demonstrates the fflush () function is used.

#include <stdio.h>
#include <string.h>

int main()
{

   char buff[1024];

   memset( buff, '\0', sizeof( buff ));

   fprintf(stdout, "启用全缓冲\n");
   setvbuf(stdout, buff, _IOFBF, 1024);

   fprintf(stdout, "这里是 w3cschool.cc\n");
   fprintf(stdout, "该输出将保存到 buff\n");
   fflush( stdout );

   fprintf(stdout, "这将在编程时出现\n");
   fprintf(stdout, "最后休眠五秒钟\n");

   sleep(5);

   return(0);
}

Let's compile and run the above program, which will produce the following results. Here, a program to save the output buffer tobuff, until the first call to fflush ()before starting a buffered output of the last 5 seconds of sleep. It will be before the end of the program, to send the remaining output to STDOUT.

启用全缓冲
这里是 w3cschool.cc
该输出将保存到 buff
这将在编程时出现
最后休眠五秒钟

C standard library - <stdio.h> C standard library - <stdio.h>