Mail Archives: djgpp/1998/09/21/08:56:02
On 20 Sep 98 at 22:36, Uhfgood wrote:
> Well here's is the simple question.  consider the following code :
> 
> printf("This demonstrates a \\a escape sequence: \a");
> getch();
> 
> Now answer me this, how come it waits until a key is pressed to display the
> string?
> 
> Now please I already know two ways to make it work like I think it's supposed
> to.
> one is to put a \n after the last part of the screen, and the other is to type
> "fflush(stdout);" but that still doesn't answer my basic question.  Please just
> explain it to me?
In djgpp v2.01, stdout (which is where `printf' sends its text)
is line buffered.  That means that what you send gets buffered
in memory until a '\n' is sent.  The buffer is also flushed if
it gets full, or if a stdio input function is called, or when
the program terminates, or when you `fflush' it manually.
So after the `printf', all your text is sitting in the buffer
-- it hasn't been sent to the screen.  Then you do a getch(),
which waits for a key to be pressed.  The text still hasn't
been printed.  In the end it is printed though because your
program terminates, or prints a '\n', ...  See the list above. 
-- 
george DOT foot AT merton DOT oxford DOT ac DOT uk
- Raw text -