int fflush (FILE * stream);
Flush a stream.
If the given stream has been opened for writing operations the output buffer is phisically written to the file.
If the stream was open for reading operations the content of the input buffer is cleared.
The stream remains open after this call.
When a file is closed all the buffers associated with it are automatically flushed. If the program terminates, every buffer is automatically flushed.
A 0 value indicates success.
If any errors occur, EOF is returned.
To demonstrate the use of fflush, we ask twice the user to input some words in a sentence. Each time the program reads the first word with scanf and flushes the rest. The next time the user is prompt the buffer will be cleared so we will be able to obtain the first word of the new sentence.
/* fflush example */
for ( n=0 ; n<2 ; n++ )
printf( "Enter some words: " );
scanf( "%s", string );
printf( "The first word you entered is : %s\n", string );
fflush ( stdin );
Enter some words: Testing this program
The first word you entered is : Testing
Enter some words: It seems to work...
The first word you entered is : It
fclose, fopen, fread, fwrite