reb2@ihlpa.UUCP (Brown) (08/22/86)
*** REPLACE THIS LINE WITH YOUR MESSAGE *** I would like to do the following: 1) Read an input file line by line and save each line in an array (using an AWK-like interface) 2) Then, within the same program, cause STDIN to point to the array so that the program can read from STDIN and get each of the saved input lines. I can do #1, but I can't think of any way to do #2. By the way, this is all being done on a PC using Microsoft C. I would greatly appreciate any help. Thanks. Rick Brown AT&T Bell Labs ihlpa!reb2
karl@haddock (09/03/86)
ihlpa!reb2 (Rick Brown) writes: >I would like to do the following: 1) Read an input file line >by line and save each line in an array (using an AWK-like >interface) 2) Then, within the same program, cause STDIN >to point to the array so that the program can read from STDIN >and get each of the saved input lines. There are some NON-PORTABLE tricks that can make a FILE* use a string rather than a file descriptor. I won't go into them here. But, if you really have an array of lines (each of which is an array of char) then you need more power than this anyway. When you're at the end of a line, you have to convert your EOL indicator ('\0', '\n', count==0, or whatever) into a newline for getc() to return, and reset your pointers to get to the next input line. I would suggest that you introduce a new type ("gfile", say) for an object that may be connected to either a string or a stdio FILE. (You could bypass the stdio FILE and use the system calls, if appropriate.) Make your own function ("ggetc()") which checks a flag member of its argument to see if it refers to a FILE (in which case it calls getc()) or an array (in which case it performs as described above). Karl W. Z. Heuer (ima!haddock!karl; karl@haddock.isc.com), The Walking Lint