input to a function
Roy Johnson
rjohnson at shell.com
Wed Jun 5 01:00:23 AEST 1991
In article <1991May30.191116.19256 at ux1.cso.uiuc.edu> nnj20229 at 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
More information about the Comp.lang.c
mailing list