Message-Id: <199809211300.OAA18969@rochefort.ns.easynet.net> Comments: Authenticated sender is From: "George Foot" To: uhfgood AT aol DOT com (Uhfgood) Date: Mon, 21 Sep 1998 04:47:07 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT 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 Precedence: bulk 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