Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!bcm!shell!shell!rjohnson From: rjohnson@shell.com (Roy Johnson) Newsgroups: comp.lang.c Subject: Re: input to a function Message-ID: Date: 4 Jun 91 15:00:23 GMT References: <1991May30.191116.19256@ux1.cso.uiuc.edu> Sender: usenet@shell.shell.com (USENET News System) Organization: Shell Development Company, Bellaire Research Center, Houston, TX Lines: 42 In-Reply-To: nnj20229@uxa.cso.uiuc.edu's message of 30 May 91 19:11:16 GMT In article <1991May30.191116.19256@ux1.cso.uiuc.edu> nnj20229@uxa.cso.uiuc.edu (Nesha Nicole Jones) writes: > > I wrote a program that acts like a grep only it greps the line you are > looking for and the line above it. I would like to be able to do > something like: > rest "restart" /usr/bin/adm/sa/sar24 > or > rest "restart" < /usr/bin/adm/sa/sar24 > > > currently my program does the second of the two listed above. If I use > file pointers and fopen will the program still work if I try to pipe input > into it? FILE *freopen(filename, type, stream) char *filename, *type; FILE *stream; freopen() opens the file named by filename and associates the stream pointed to by stream with it. The type argument is used just as in fopen. The original stream is closed, regardless of whether the open ultimately succeeds. If the open succeeds, freopen() returns the original value of stream. freopen() is typically used to attach the preopened streams associated with stdin, stdout, and stderr to other files. So if ((argc == 3) && (freopen(argv[2], "r", stdin) != stdin)) { perror(argv[2]); exit(1); } in your command line parsing phase should make the file opening transparent to your program (no messy FILE pointers). -- =============== !You!can't!get!here!from!there!rjohnson =============== Feel free to correct me, but don't preface your correction with "BZZT!" Roy Johnson, Shell Development Company