bbuuffffeerr -- Definition

A _b_u_f_f_e_r is  a portion of memory set aside to  hold data read from or to be
written to  another process  or device.   Often, although not  always, this
involves setting  aside a portion of  the arena with mmaalllloocc  or its related
functions.

Buffering, and  problems therewith, are  encountered most often  when using
the  standard input  and output (STDIO)  routines.  Many  operating systems
(including COHERENT) automatically place data from a peripheral device into
a buffer.   Buffers normally can be cleared with  fffflluusshh(), by pressing the
carriage return key on routines that perform input, or by sending a newline
character on  routines that perform  output.  The function  ffcclloossee(), which
closes  a file  stream, flushes  all buffers  associated with  that stream.
eexxiitt() calls ffcclloossee().

Combining unbuffered and buffered I/O  functions on the same file or device
within one program will produce results that are at best unpredictable.

_E_x_a_m_p_l_e
The following  example demonstrates what does and does  not happen when you
use fffflluusshh() with the output buffer.

#include <stdio.h>
main()
{
    extern char *malloc();
    char *buffer;

    /* use malloc() to create a 120-char buffer */
    if ((buffer = malloc(120)) == NULL) {
        /* if malloc() fails, bail out */
        fprintf(stderr, "malloc failed\n");
        exit(1);
    }

    printf("Type your name:  ");
    fflush(stdout);
    gets(buffer);
    printf("Your name is %s\n", buffer);
}

_S_e_e _A_l_s_o
aarreennaa, aarrrraayy, cclloossee, eexxiitt, fffflluusshh, mmaalllloocc, PPrrooggrraammmmiinngg CCOOHHEERREENNTT, ssttddiioo.hh
