Path: utzoo!attcan!uunet!cs.utexas.edu!rutgers!uwvax!tank!uxc!uxc.cso.uiuc.edu!ux1.cso.uiuc.edu!osiris.cso.uiuc.edu!hamilton From: hamilton@osiris.cso.uiuc.edu Newsgroups: comp.lang.c Subject: Re: File descriptors and streams and co Message-ID: <1239500006@osiris.cso.uiuc.edu> Date: 25 Apr 89 23:23:00 GMT References: <1743@leah.Albany.Edu> Lines: 42 Nf-ID: #R:leah.Albany.Edu:1743:osiris.cso.uiuc.edu:1239500006:000:865 Nf-From: osiris.cso.uiuc.edu!hamilton Apr 25 18:23:00 1989 rds95@leah.Albany.Edu says: > I want to be able to make "stdin" read from someplace besides, well, > standard input in the middle of my program, and then go back to where > it was again. i would do it like this: void fexchange(a, b) FILE *a; FILE *b; { FILE tmp; tmp = *a; *a = *b; *b = tmp; } FILE *my_file; /* open my_file */ /* exchange stdin & my_file */ fexchange(stdin, my_file); /* ... use stdin ... */ /* restore stdin */ fexchange(stdin, my_file); fclose(my_file); i've been using this technique for years in an application where i wanted a nested "#include" capability for interactive input. wayne hamilton U of Il and US Army Corps of Engineers CERL UUCP: {convex,uunet}!uiucuxc!osiris!hamilton ARPA: hamilton@osiris.cso.uiuc.edu USMail: Box 476, Urbana, IL 61801 CSNET: hamilton%osiris@uiuc.csnet Phone: (217)333-8703