Mail Archives: djgpp/1998/10/05/19:53:13
On Mon, 5 Oct 1998, Chris Yewchuk wrote:
> The problem is that no text is printed to the screen until the program
> terminates. Almost like there is an output buffer that isn't being
> flushed until the program terminates. The getch()'s work okay, but
> there is no text until the end of the program, at which time all the
> text that was supposed to be displayed throughou the program is dumped
> as one long string.
That is exactly what is happening.
> Has anyone encountered this before? I'm tried using printf and cout for
> printing to stdout. Am i doing something wrong?
By default stdout is line buffered. This means that nothing
gets printed until (1) the buffer is full; (2) a newline
character is sent; (3) the buffer is flushed. The buffer can be
flushed in C by calling fflush(stdout). I don't know about C++.
The buffer is automatically flushed by stdio functions like
`scanf', but not by conio functions like `getch'. It's best to
avoid mixing stdio and conio input/output functions.
Possible solutions if you want to continue mixing the functions:
a) Turn off the buffering on startup (`setvbuf' can do this)
b) Explicitly flush the buffer (`fflush(stdout)')
c) Send a newline character ('\n')
Even after using any of these, it's best not to mix the
functions.
--
george DOT foot AT merton DOT oxford DOT ac DOT uk
xu do tavla fo la lojban -- http://xiron.pc.helsinki.fi/lojban/lojban.html
- Raw text -