Richard said:
guoliang said:
If you want the prompt to appear before the program blocks for input,
ensure that this happens, either by completing the line or by flushing
the stream with fflush(stdout); this is because the standard output
stream is typically line-buffered.
That's a thing I believed until recently, but now, I'm not anymore.
Unable to find a printf()+scanf() series that came to fail to display
the prompting message on time, I searched the Jan'99 Draft
and found this:
---------------------------
5.1.2.3 Environment (p. 18)
-- The input and output dynamics of interactive devices
shall take place as specified in 7.19.3. The intent of
these requirements is that unbuffered or line-buffered
output appear as soon as possible, to ensure that
prompting messages actually appear prior to a program
waiting for input.
7.19.3 File (p. 270)
[#3] When a stream is unbuffered, characters are intended to
appear from the source or at the destination as soon as
possible. Otherwise characters may be accumulated and
transmitted to or from the host environment as a block.
When a stream is fully buffered, characters are intended to
be transmitted to or from the host environment as a block
when a buffer is filled. When a stream is line buffered,
characters are intended to be transmitted to or from the
host environment as a block when a new-line character is
encountered. Furthermore, characters are intended to be
transmitted as a block to the host environment when a buffer
is filled, when input is requested on an unbuffered stream,
* or when input is requested on a line buffered stream that
requires the transmission of characters from the host
environment.*
Support for these characteristics is
implementation-defined, and may be affected via the setbuf
and setvbuf functions.