delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/09/21/08:56:02

Message-Id: <199809211300.OAA18969@rochefort.ns.easynet.net>
Comments: Authenticated sender is <mert0407 AT sable DOT ox DOT ac DOT uk>
From: "George Foot" <george DOT foot AT merton DOT ox DOT ac DOT uk>
To: uhfgood AT aol DOT com (Uhfgood)
Date: Mon, 21 Sep 1998 04:47:07 +0000
MIME-Version: 1.0
Subject: Re: Simple C question probably having to do with DJGPP
Reply-to: mert0407 AT sable DOT ox DOT ac DOT uk
CC: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019