Mail Archives: djgpp/1998/01/26/04:11:24
> 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 -