unix question about stdin
Leslie Mikesell
les at chinet.chi.il.us
Mon Apr 24 14:23:31 AEST 1989
In article <3398 at udccvax1.acs.udel.EDU> conan at vax1.acs.udel.EDU (Robert B Carroll) writes:
>Once stdin is closed, how do you open it up again so that
>all the stdio functions(scanf, gets etc. etc. etc.) will work
>via a terminal keyboard? to explain it in more detail, my C
>program:
>1) reads user info typed in from keyboard
>2) does a freopen and acts like a file is now standard input
>3) then i need to 'make' standard input be the keyboard so that
> i can get info typed in from the keyboard again.
One way is to dup(2) the original file descriptor to hold a copy before
the freopen. To get it back, close(0); dup(copy);. There might be
some problems with buffered input if you had not read to EOF on the
alternate stream.
Les Mikesell
More information about the Comp.unix.wizards
mailing list