mardi 25 mars 2014

Re: Read from stdin without affecting stream position topic




fabio wrote:
> Hello,
>
> 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.
>
> Thank you


It isn't clear to me why the store-in-an-array answer can't be used in
two different parts of a program.

Why can't getc and ungetc be used?

--
Madam Life's a piece in bloom,
Death goes dogging everywhere:
She's the tenant of the room,
He's the ruffian on the stair.





Aucun commentaire:

Enregistrer un commentaire