mardi 25 mars 2014

Re: Read from stdin without affecting stream position topic




fabio <(E-Mail Removed)> writes:
> I have this code:
>
> fd_set rfds;
> struct timeval tv;
> FD_ZERO(&rfds);
> FD_SET(0, &rfds);
> tv.tv_sec = 0; tv.tv_usec = 0;
> int retval = select(1, &rfds, NULL, NULL, &tv);
> if (retval && retval!=-1)
> {
> ....
> }
>
> I check if the stdin is ready to be read without blocking.
> I need now to read what has been sent to stdin but I don't want to use
> fgets because affect the stream position and I cannot read another time
> what has been sent.
> So what is the rigth function to read from stdin that let me the chance
> to read another time the same thing from stdin with fgets?
> I cannot use an array and store the result from an fgets because I need
> it in two different part of the program.


You're using feature that aren't defined by the C language standard.

You're likely to get better answers in comp.unix.programmer.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"





Aucun commentaire:

Enregistrer un commentaire