#include <stdio.h> int fflush(FILE *f);
fflush
flushes the output buffer for the stream associated with
the FILE
object addressed by f
. The exact effect of
fflush
depends on the file type and stream type, as follows:
fflush
has no effect.
Passing the output buffer to the operating system also forces a record break,
which should occur only when a new-line character is written.
If you do not use fflush
, output buffers are flushed as follows:
The effect of fflush
on a read-only file is undefined.
fflush
returns 0, or EOF
if an error occurs.
fflush
is portable when used to ensure that output to an
interactive device is written out. The use of fflush
on other
files, such as disk files, does not guarantee immediate I/O, and using
fflush
to force record breaks is completely nonportable.
#include <stdio.h> #include <stdlib.h> main() { long partno; fputs("Enter part number:", stdout); fflush(stdout); /* Force prompt to terminal. */ scanf("%ld", &partno); /* Read the part number. */ ptintf("Request for part # %ld received.", partno); }
afflush
, fsync
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.