Re: Getting user input in Linux?
- From: roberson@xxxxxxxxxxxxxxxxxx (Walter Roberson)
- Date: Thu, 31 Jan 2008 15:21:31 +0000 (UTC)
In article <fnrta7$aqb$1@xxxxxxxxx>,
Joachim Schmitz <jojo@xxxxxxxxxxxxxxxxxx> wrote:
Walter Roberson wrote:
In article
<695fa4aa-12b5-4128-93cf-64c76594dffb@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Zach <netrek@xxxxxxxxx> wrote:
printf("Enter first integer: %d\n",s1);
scanf(&s1);
After that you do nothing special before you try to read some
data. However, if you want your output to appear before the
read starts happening, you have to call fflush(stdout)
the '\n' in the printf should have done than.
The '\n' in the printf would only have that effect if the
output was line-buffered or unbuffered instead of file-buffered.
The default for streams is file-buffering, except when the
system can detect that the stream is connected to a "terminal".
What a "terminal" is and whether it can be reliably detected is
not defined by the standard. It is safer to assume that detection
is unreliable and to fflush(stdout) manually.
Historically, there has been interactive usage that was not
reliably detected, such as in the earlier generations of operations
of unix pseudo-terminals (ptys).
--
"There are some ideas so wrong that only a very intelligent person
could believe in them." -- George Orwell
.
- Follow-Ups:
- Re: Getting user input in Linux?
- From: Harald van Dijk
- Re: Getting user input in Linux?
- References:
- Getting user input in Linux?
- From: Zach
- Re: Getting user input in Linux?
- From: Walter Roberson
- Re: Getting user input in Linux?
- From: Joachim Schmitz
- Getting user input in Linux?
- Prev by Date: Re: Type conversion
- Next by Date: Reverse biwise operation and xor?
- Previous by thread: Re: Getting user input in Linux?
- Next by thread: Re: Getting user input in Linux?
- Index(es):