www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/26/04:11:24

From: G DOT DegliEsposti AT ads DOT it
To: djgpp AT delorie DOT com
Message-ID: <C1256598.00321C7E.00@vega.ads.it>
Date: Mon, 26 Jan 1998 10:10:34 +0100
Subject: Re: printf/getch problem
Mime-Version: 1.0




>   Whenever I have a  printf before a getch, it waits until a key is
>pressed before printing the string. However, if the string ends with a
>\n it works fine.
>
>e.g  printf("blah");
>       getch();
>
>will wait for a key to be pressed and then print "blah". If I replace
>it with "blah\n" it works.
>
>  Is this supposed to happen and if so how do I get around it? I've
>tried the same thing with a borland compiler and it works as expected.

This happens because the output is buffered, i.e. the chars are put on
the screen after a whole line is printed (this explins why your code
works with \n and doesn't without)

You can override this using "fflush(stdout)", which outputs the
output buffer even if it doesn't contain a whole line.

ciao
  Giacomo




- Raw text -


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