Mail Archives: djgpp/1998/01/26/04:15:32
tg wrote:
>
> 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.
Welcome to the world of UNIXy file buffering. If you had read the
FAQ, you would have found that the solution is to
fflush(stdout);
if your string doesn't end with a newline.
BTW, Eli, wouldn't it be better to leave out _which_ section
to in the FAQ? Then people might at least take a longer glance
at it and hopefully understand a few more things?
And why the hell are you working on sundays? ;-)
--
Ciao
Tom
*************************************************************
* Thomas Demmer *
* Lehrstuhl fuer Stroemungsmechanik *
* Ruhr-Uni-Bochum *
* Universitaetsstr. 150 *
* D-44780 Bochum *
* Tel: +49 234 700 6434 *
* Fax: +49 234 709 4162 *
* http://www.lstm.ruhr-uni-bochum.de/~demmer *
*************************************************************
- Raw text -