delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/08/08:26:17

Message-Id: <3.0.16.19971008142347.356f2b4e@hem1.passagen.se>
Date: Wed, 08 Oct 1997 14:23:50 -0400
To: "Newbie" <new AT no_spam DOT com>
From: Peter Palotas <blizzar AT hem1 DOT passagen DOT se>
Subject: Re: Why don't printf work properly with getch ()?
Cc: djgpp AT delorie DOT com
Mime-Version: 1.0

At 02.06 1997-10-08 GMT, you wrote:
>I had some problem with printf and getch working together.
>Seems to me that the last printf preceeding a getch is executed only after
>a key is pressed.
>
>examples:
>	printf ("\n1");
>	printf ("\n2");
>	printf ("\n3");
>	getch ();
>would produce
>1
>2
>waiting for keystroke, 
>after a key is pressed
>3
>
>Is this a know bug with djgpp? Is there any way to work around this?
>Thanks.

This is not a bug. This is because printf() (stdout) is buffered in DJGPP,
which means that it doesn't print the data until you flush it
(fflush(stdout);) or when a newline is found.

So either you put an fflush(stdout) in front of getch(), or you put the
newlines last in each string, or you use cprintf() instead.

This issue is covered in the FAQ too, look it up there!


-- Peter Palotas alias Blizzar -- blizzar AT hem1 DOT passagen DOT se --

*****************************************************
* A brief description of DJGPP:                     *
* NEVER BEFORE HAS SO FEW DONE SO MUCH FOR SO MANY! *
*****************************************************

- Raw text -


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