|
|
coherent
fflush() STDIO Function fflush()
Flush output stream's buffer
#include <stdio.h>
iinntt fffflluusshh(_f_p) FFIILLEE *_f_p;
fflush flushes any buffered output data associated with the file
stream fp. The file stream stays open after fflush is called.
fclose calls fflush, so there is no need for you to call it when
normally closing a file or buffer.
***** Example *****
This example demonstrates fflush. 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 foo 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 exit().
COHERENT Lexicon Page 1
fflush() STDIO Function fflush()
Although the COHERENT screen drivers print all output im-
mediately, not all operating systems work this way, so when in
doubt, fflush().
#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");
}
***** See Also *****
fclose(), setbuf(), STDIO, write()
***** Diagnostics *****
fflush returns EOF if it cannot flush the contents of the buff-
ers; otherwise it returns a meaningless value.
Note, also, that all STDIO routines are buffered. fflush should
be used to flush the output buffer if you follow a STDIO routine
with an unbuffered routine.
COHERENT Lexicon Page 2
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.