Reading stdin

O

orium69

Hi!
how could i know if it was written something in stdin since the last
time i read it?

Tks...
 
R

rayw

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
 
O

orium69

rayw said:
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...
 
P

pemo

rayw said:
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???
 
F

Flash Gordon

rayw said:
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.
 
E

Emmanuel Delahaye

(e-mail address 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)
 
H

Herbert Rosenau

rayw said:
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top