Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!ames!amdahl!pacbell!att!chinet!les From: les@chinet.chi.il.us (Leslie Mikesell) Newsgroups: comp.unix.wizards Subject: Re: unix question about stdin Message-ID: <8283@chinet.chi.il.us> Date: 24 Apr 89 04:23:31 GMT References: <3398@udccvax1.acs.udel.EDU> Reply-To: les@chinet.chi.il.us (Leslie Mikesell) Organization: Chinet - Public Access Unix Lines: 17 In article <3398@udccvax1.acs.udel.EDU> conan@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