Share via


fflush (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference

Flushes a stream.

int fflush(    FILE*stream);

Parameters

  • stream
    Pointer to FILE structure.

Return Values

fflush returns 0 if the buffer is successfully flushed, if the specified stream has no buffer, or if the stream is open for reading only.

A return value of EOF indicates an error.

Note   If fflush returns EOF, data might be lost due to a write failure. When setting up a critical error handler, it is safest to turn buffering off with the setvbuf function.

Remarks

The fflush function flushes a stream.

If the file associated with stream is open for output, fflush writes to that file the contents of the buffer associated with the stream.

If the stream is open for input, fflush clears the contents of the buffer.

fflush negates the effect of any prior call to ungetc against stream. Also, fflush(NULL) flushes all streams open for output. The stream remains open after the call.

fflush has no effect on an unbuffered stream.

Buffers are normally maintained by the operating system, which determines the optimal time to write the data automatically to disk: when a buffer is full, when a stream is closed, or when a program terminates normally without closing the stream.

For information about controlling the commit-to-disk feature, see fopen.

Example

/* FFLUSH.C */

#include <stdio.h>
#include <conio.h>

void main( void )
{
   int integer;
   char string[81];

   /* Read each word as a string. */
   printf( "Enter a sentence of four words with scanf: " );
   for( integer = 0; integer < 4; integer++ )
   {
      scanf( "%s", string );
      printf( "%s\n", string );
   }

   /* You must flush the input buffer before using gets. */
   fflush( stdin );
   printf( "Enter the same sentence with gets: " );
   gets( string );
   printf( "%s\n", string );
}

Output

Enter a sentence of four words with scanf: This is a test
This
is
a
test
Enter the same sentence with gets: This is a test
This is a test
//

Requirements

OS Versions: Windows CE 2.0 and later.
Header: stdlib.h.
Link Library: coredll.dll.

See Also

fclose | _flushall | setvbuf

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.