Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Reading stdin

Reply
Thread Tools

Reading stdin

 
 
orium69@gmail.com
Guest
Posts: n/a
 
      01-04-2006
Hi!
how could i know if it was written something in stdin since the last
time i read it?

Tks...

 
Reply With Quote
 
 
 
 
rayw
Guest
Posts: n/a
 
      01-04-2006

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hi!
> how could i know if it was written something in stdin since the last
> time i read it?


Not quite sure I've got this right, but you're asking [?] if I've read
stdin - until it's empty, how can I then determine whether something else is
waiting there to be read?

Well, I guess you'd try to read something from stdin


 
Reply With Quote
 
 
 
 
peet.morris@gmail.com
Guest
Posts: n/a
 
      01-04-2006

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi!
> how could i know if it was written something in stdin since the last
> time i read it?


See the related ...

http://groups.google.com/group/comp....20c69760e4b553

 
Reply With Quote
 
orium69@gmail.com
Guest
Posts: n/a
 
      01-04-2006
rayw wrote:
> Not quite sure I've got this right, but you're asking [?] if I've read
> stdin - until it's empty, how can I then determine whether something else is
> waiting there to be read?
>
> Well, I guess you'd try to read something from stdin


My problem is that I need to read from stdin only if is something to
read, i don want to break the program until somebody type something...

 
Reply With Quote
 
pemo
Guest
Posts: n/a
 
      01-04-2006

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> rayw wrote:
>> Not quite sure I've got this right, but you're asking [?] if I've read
>> stdin - until it's empty, how can I then determine whether something else
>> is
>> waiting there to be read?
>>
>> Well, I guess you'd try to read something from stdin

>
> My problem is that I need to read from stdin only if is something to
> read, i don want to break the program until somebody type something...


Sadly, you cannot monitor stdin [sadly] using a standard function without
*perhaps* causing a 'wait'.

What's you're OS - as they'll most likely be someway to this under that???


 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      01-04-2006
rayw wrote:
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
>> Hi!
>> how could i know if it was written something in stdin since the last
>> time i read it?

>
> Not quite sure I've got this right, but you're asking [?] if I've read
> stdin - until it's empty, how can I then determine whether something else is
> waiting there to be read?
>
> Well, I guess you'd try to read something from stdin


Which, unfortunately for the OP, does not tell you if anything more has
been written to it (e.g. the user types something else, or more data in
the pipe, or whatever) but instead makes your program wait until either
end-of-file, an error condition, or some more data is entered.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
 
Reply With Quote
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      01-04-2006
(E-Mail Removed) a écrit :
> My problem is that I need to read from stdin only if is something to
> read, i don want to break the program until somebody type something...


Can't do that in standard C. If you can, see select() or poll() (it's
POSIX, hence very portable)

--
A+

Emmanuel Delahaye
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-05-2006
(E-Mail Removed) writes:
> how could i know if it was written something in stdin since the last
> time i read it?


The C FAQ is at <http://www.c-faq.com/>. You've asked question 19.2.

(Don't people cite the FAQ anymore?)

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
Herbert Rosenau
Guest
Posts: n/a
 
      01-06-2006
On Wed, 4 Jan 2006 22:05:43 UTC, (E-Mail Removed) wrote:

> rayw wrote:
> > Not quite sure I've got this right, but you're asking [?] if I've read
> > stdin - until it's empty, how can I then determine whether something else is
> > waiting there to be read?
> >
> > Well, I guess you'd try to read something from stdin

>
> My problem is that I need to read from stdin only if is something to
> read, i don want to break the program until somebody type something...
>

Impossible mission. There is nothing in standard C that defines that
stdin is a device that will do what you thinks. stdin may return data
until EOF is reached and nothing else thereafter or it may block the
program until some new data arrives from anywhere it is bounded to or
it may behave something else depending on the API you uses to read
from stdin. It may even change its behavior from run to run depending
on the device or file stdin is bounded to.

C knows nothing about keyboards, punch cards, files, or other devices.
stdin is simply an abstract stream that will serve a stream of
characters until EOF is reached.

When you really needs a specific behavior check the documentation of
the system your program is running under and look if (or if not) that
specific system gives you an API that does what you asks for.



--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
peek at stdin, flush stdin Johnathan Doe C Programming 5 05-17-2013 04:30 PM
How to pass stdin of a C++ program to the stdin of a process createdwith ShellExecute() Ben C Programming 2 08-29-2009 09:47 PM
STDIN, OUT, ERR and $stdin, out, err - Differences? Terry Cooper Ruby 7 06-09-2009 05:48 AM
Reading from stdin then launching a program that reads from stdin strange behaviour Stefano Sabatini Perl Misc 6 07-29-2007 10:38 PM
Reading stdin once confuses second stdin read Charlie Zender C Programming 6 06-21-2004 01:39 PM



Advertisments