fflush - C stdio.h

C examples for stdio.h:fflush

Type

function

From


<cstdio>
<stdio.h>

Prototype

int fflush ( FILE * stream );

Description

Writing any unwritten data in its output buffer to the file.

Parameters

ParameterDescription
stream Pointer to a FILE object that specifies a buffered stream.

Return Value

A zero value indicates success.

If an error occurs, EOF is returned and the error indicator is set (see ferror).

Demo Code

#include <stdio.h>

char mybuffer[80];

int main()/*from   w  ww .j a  va2 s . com*/
{
   FILE * pFile;
   pFile = fopen ("example.txt","r+");
   if (pFile == NULL) {
      perror ("Error opening file");
      return -1;
   }
   fputs ("test",pFile);
   fflush (pFile);    // flushing or repositioning required
   fgets (mybuffer,80,pFile);
   puts (mybuffer);
   fclose (pFile);
   return 0;

}

Related Tutorials