Afficher un message
Vieux 31/01/2008, 16h21   #6
Walter Roberson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting user input in Linux?

In article <fnrta7$aqb$1@online.de>,
Joachim Schmitz <jojo@schmitz-digital.de> wrote:
>Walter Roberson wrote:
>> In article
>> <695fa4aa-12b5-4128-93cf-64c76594dffb@m34g2000hsb.googlegroups.com>,
>> Zach <netrek@gmail.com> 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
  Réponse avec citation
 
Page generated in 0,05636 seconds with 9 queries