fffflluusshh() -- STDIO Function (libc)

Flush output stream's buffer
#iinncclluuddee <ssttddiioo.hh>
iinntt fffflluusshh(_f_p) FFIILLEE *_f_p;

fffflluusshh() flushes  any buffered output data associated  with the file stream
_f_p. The  file stream stays  open after fffflluusshh() is  called.  ffcclloossee() calls
fffflluusshh(), so  there is no need  for you to call it  when normally closing a
file or buffer.

_E_x_a_m_p_l_e
This example demonstrates fffflluusshh(). When run, you will see the following:

    Line 1
    -----
    Line 1
    -----
    Line 1
    Line 2
    -----

The call

    fprintf(fp, "Line 2\n");

goes to a  buffer and is not in the  file when file ffoooo is listed.  However
if you redirect the output of this program to a file and list the file, you
will see:

    Line 1
    Line 1
    Line 1
    Line 2
    -----
    -----
    -----

because the line

    printf("-----\n");

goes into  a buffer and  is not printed  until the program is  over and all
buffers are flushed by eexxiitt().

Although the COHERENT screen  drivers print all output immediately, not all
operating systems work this way, so when in doubt, fffflluusshh().

#include <stdio.h>

main()
{
    FILE *fp;

    if (NULL == (fp = fopen("foo", "w")))
        exit(1);
    fprintf (fp, "Line 1\n");
    fflush (fp);
    system ("cat foo"); /* print Line 1 */

    printf("-----\n");
    fprintf(fp, "Line 2\n");
    system("cat foo"); /* print Line 1 */
    printf("-----\n");

    fflush(fp);
    system("cat foo"); /* print Line 1 Line 2 */
    printf("-----\n");
}

_S_e_e _A_l_s_o
ffcclloossee(), lliibbcc, sseettbbuuff(), wwrriittee()
ANSI Standard, section 7.9.5.2
POSIX Standard, section 8.1

_D_i_a_g_n_o_s_t_i_c_s
fffflluusshh()  returns EEOOFF  if  it cannot  flush  the contents  of the  buffers;
otherwise it returns a meaningless value.

Note, also, that all STDIO  routines are buffered.  fffflluusshh() should be used
to flush the output buffer if you follow a STDIO routine with an unbuffered
routine.
