Mail Archives: djgpp/1998/01/26/10:00:23
tg wrote in message <34cc2c99 DOT 1842074 AT news DOT telusplanet DOT net>...
> 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.
>
The output in your printf statement was actually buffered (In DJGPP)
When you use a new line '\n' , the buffer was actually flushed. If no new
line character was used , the output is buffered while getch() was executed.
To force a flush (if you don't want to use '\n') , use fflush(stdout)
Hence ,
printf("blah");
fflush(stdout);
getch();
Should work.
Regards,
Kean
- Raw text -