Path: utzoo!dptcdc!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!uxc!uxc.cso.uiuc.edu!m.cs.uiuc.edu!s.cs.uiuc.edu!carroll From: carroll@s.cs.uiuc.edu Newsgroups: comp.lang.c Subject: Re: File descriptors and streams and co Message-ID: <207600018@s.cs.uiuc.edu> Date: 16 Apr 89 23:32:00 GMT References: <1743@leah.Albany.Edu> Lines: 24 Nf-ID: #R:leah.Albany.Edu:1743:s.cs.uiuc.edu:207600018:000:1068 Nf-From: s.cs.uiuc.edu!carroll Apr 16 18:32:00 1989 I must be missing something - given that FILE *my_file; has been properly set up (with fopen(), no errors, etc.), why can't you switch stdin by having another variable FILE *tmp; and doing tmp = stdin; stdin = my_file; 'stdin' is declared as a pointer, and so setting the pointer to point at a different FILE I/O block should cause routines that use it to read from that file instead. You can then restore by stdin = tmp; Mr. Salz indicated that things are more complex than this. Is this because of library routines with file descriptor 0 wired in, or because file info is kept in places other than the FILE I/O block stdin points to? While this might not work in all cases, it seems to me it should in the original case, if twiddling the file descriptor in the block works. (i.e., it must not be hard-wired and must look in the FILE I/O block for things). Alan M. Carroll "And then you say, carroll@s.cs.uiuc.edu We have the Moon, so now the Stars..." - YES CS Grad / U of Ill @ Urbana ...{ucbvax,pur-ee,convex}!s.cs.uiuc.edu!carroll