www.delorie.com/djgpp/v2faq/faq077.html | search |
| Previous | Next | Up | Top |
Q: Help! I cannot make `gotoxy' work! The text I print appears on the screen in incorrect locations after I use `gotoxy'!
Q: Why does the text appear in the default colors even though I call `textcolor' and `textbackground'?
fprintf
, fputs
and the like) functions, or send your output to the C++ cout
stream? Then what you see is the effect of the buffering of the standard output streams. The buffer is not written to screen until it's full, or until a newline is output, which might produce very
unpleasant and unexpected behavior when used in interactive programs.
It is usually a bad idea to use buffered I/O in interactive programs; you should instead use screen-oriented functions like cprintf
and cputs.
If you must use buffered I/O,
you should be sure that both stdout
and stderr
are line-buffered or unbuffered (you can change the buffering by calling the setvbuf
library function); another
solution would be to fflush
the output stream before calling any input function, which will ensure all pending output is written to the operating system. While this will generally work
under DOS and DJGPP, note that in some cases the operating system might further buffer your output, so sometimes a call like sync
would be needed to actually cause the output be
delivered to the screen.
The functions that set text attributes only affect the screen-oriented output (a.k.a. conio) functions (cputs
, cprintf
etc.), the text written by
fprintf
and other stdio functions doesn't change. This is unlike some 16-bit DOS compilers where stdio
functions can also print colored text.
webmaster donations bookstore | delorie software privacy |
Copyright ⌐ 1998 by Eli Zaretskii | Updated Sep 1998 |
You can help support this site by visiting the advertisers that sponsor it! (only once each, though)