Article View: net.lang.c
Article #9230Re: Arrays as files
From: karl
Date: Wed, 03 Sep 1986 18:27
Date: Wed, 03 Sep 1986 18:27
25 lines
1783 bytes
1783 bytes
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
Technical Details
Message-ID:
<86900033@haddock>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!think!ima!haddock!karlReferences:
<1718@ihlpa.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!think!ima!haddock!karl From: karl@haddock Newsgroups: net.lang.c Subject: Re: Arrays as files Message-ID: <86900033@haddock> Date: Wed, 3-Sep-86 14:27:00 EDT Article-I.D.: haddock.86900033 Posted: Wed Sep 3 14:27:00 1986 Date-Received: Wed, 3-Sep-86 21:51:51 EDT References: <1718@ihlpa.UUCP> Lines: 25 Nf-ID: #R:ihlpa.UUCP:1718:haddock:86900033:000:1259 Nf-From: haddock!karl Sep 3 14:27:00 1986