File I/O with lex/yacc
George Bogatko
bogatko at lzga.ATT.COM
Thu Aug 30 22:22:33 AEST 1990
In article <1990Aug29.172830.14348 at cunixf.cc.columbia.edu>, gld at cunixd.cc.columbia.edu (Gary L Dare) writes:
>
> Is there any way to get around the use of standard input/output in a
> lex file??? The C file generated by lex (from the lexical analyzer
There are two ways.
1. Use freopen(...stdin) freopen(...stdout).
freopen("your_in_file", "r", stdin);
freopen("your_out_file", "w", stderr;
2. use a close/open combination, ala:
close(0);
open("your_in_file", ...);
close(1);
open("your_out_file", ...);
blah, blah, blah.
the second way can be useful if you want to use lex to parse the input from
a tty line different than your terminal line.
Method 1 is far less messy than method 2.
GB
More information about the Comp.unix.questions
mailing list