#include <stdio.h> ret = fflush( f );
"fflush" flushes buffered output for the file "f". The file remains open. This version of "fflush" works on terminals, disk files, and SYSOUT.
A "fflush" operation on a disk file involves a fair amount of overhead. Therefore you should not flush disk files explicitly unless the nature of the application makes it necessary (for example, if you need to flush log files to make sure they remain valid in the event of a system crash).
A "fflush" operation on a terminal also costs significant overhead, unless there is no output waiting to go to the terminal. You should generally avoid explicit flush operations on terminals, since it might make you lose input. For example, you should definitely NOT write code of the form
printf("Prompt: "); fflush(stdout); gets(s);
The reason is that input to the terminal is discarded unless there is an outstanding read request from the program. Since the flush operation takes place between the "printf" and the "gets", any input received after the prompt but before the "gets" is simply discarded. It is much safer to write
printf("Prompt: "); gets(s);
and let the implicit output-flushing routines handle everything for you.
expl c lib sleep
Copyright © 1996, Thinkage Ltd.