The function fflush is used for flushing the stream’s output buffer; that is, it is used to immediately flush the contents present in any of the buffered stream to the corresponding file. It will return zero if successful, else it returns EOF, and the error indicator will be a set, such as feof.

Syntax:

1

2

3

int fflush (FILE * stream)

where;

Stream — pointer to a FILE object that specifies a buffered stream.

Stream points to an output stream or an update stream in which operation was not an input. Fflush causes any unwritten data of that stream to be delivered to the other host environment to be written into the file; else will cause undefined behavior.

Fflush will write the contents of the stdout buffer immediately to the output file instead of a newline buffered writing by default. This should not be used on any of the input streams as it is prone to undefined behavior. Fflush(stream) is defined as output streams; hence, fflush(stdout) will work fine, but fflush(stdin) does not.

Consider an instance that includes fflush(stdin):

#include <stdio.h>

#include <conio.h>

#include <string.h>

int main()

{

char s[20] = “JavaTPoint”;

printf (“The string is: %s”, s);

fflush(stdin);

return 0;

}