473,385 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Reading stdin

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

Tks...

Jan 4 '06 #1
8 3878

<or*****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr 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
Jan 4 '06 #2

or*****@gmail.com 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

Jan 4 '06 #3
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...

Jan 4 '06 #4

<or*****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr 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???
Jan 4 '06 #5
or*****@gmail.com 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
Jan 4 '06 #6
rayw wrote:
<or*****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr 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.
Jan 4 '06 #7
or*****@gmail.com 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) ks***@mib.org <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.
Jan 5 '06 #8
On Wed, 4 Jan 2006 22:05:43 UTC, or*****@gmail.com 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!
Jan 6 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bernhard Kuemel | last post by:
Hi! I want to read/write commands and program input to/from /bin/bash several times before I close the stdin pipe. However, reading from cat hangs unless I first close the stdin pipe. <?php...
1
by: Scott Shaw | last post by:
Hi all, I was wondering if you could help out with this problem that I am having. What I am trying to do is detect keyboard input in a while loop without halting/pausing the loop until the key is...
1
by: Lisa C | last post by:
Hi all. I am trying to set up a C++ program which will continuously read stdin from another applications stdout. I will continue reading until I read a message that will indicate to stop. Does...
6
by: chad kline | last post by:
FBSD 4.8/GCC //////// C-CODE: //////// char c; while ( 1 ) {
6
by: Charlie Zender | last post by:
Hi, I have a program which takes the output filename argument from stdin. Once the program knows the output filename, it tries to open it. If the output file exists, the program asks the user to...
3
by: joshuawilsonster | last post by:
All, I'm hoping you can provide some help. I have opened a temporary file, written to it, verified the correct amount was written, done freopen() for the file to stdin, then try read the...
25
by: 7stud | last post by:
I can't break out of the for loop in this example: ------ import sys lst = for line in sys.stdin: lst.append(line) break
3
by: Jon Harrop | last post by:
I can read bytes from a FileStream with stream.ReadByte() but that does not handle stdin. I can read from stdin with System.Console.In using reader.Read() but it is 6x slower. So how do I read...
5
by: Luis Zarrabeitia | last post by:
I have a problem with this piece of code: ==== import sys for line in sys.stdin: print "You said!", line ==== Namely, it seems that the stdin buffers the input, so there is no reply until ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.