Mail Archives: djgpp/1996/04/24/14:01:29
Gregory Fedor (gfedor AT lerc DOT nasa DOT gov) wrote:
: I wrote some simple code that utilizes the gotoxy() and printf()
: statements to place text on the screen, ala:
: while(!done)
: {
: gotoxy(column, line);
: printf(" %... ", ...);
: // update column
: // update line
: }
: When I run this type of code nothing appears on the screen. I can see
: the cursor jumping around, but nothing else. However, if I include a
: '\n' in the printf statement, things display fine, *or* as soon as I
: printf with a '\n' outside the loop, then **all** the text gets
: displayed. It's almost as if it's being buffered, and isn't displayed
: until a '\n' comes along.
This is because the stdout stream is line buffered by default. So the output
is flushed when the buffer is full (1024 chars or something) or if a \n
is printed. To flush the buffer explicitly, you can use the fflush function.
Another possibility is to set stdout to non-buffered mode, but this way the
output becomes slower (since it is done char-by-char), so the first solution
is usually favorable.
bye, Alexander
--
Alexander Lehmann, | "On the Internet,
alex AT hal DOT rhein-main DOT de (plain, MIME, NeXT) | nobody knows
alexlehm AT rbg DOT informatik DOT th-darmstadt DOT de (plain) | you're a dog."
<URL:http://www.student.informatik.th-darmstadt.de/~alexlehm/>
- Raw text -