[Courses] [C] Beginner's Lesson: How do I...?

KWMelvin kwmelvin at intrex.net
Fri Dec 13 17:26:04 EST 2002


On Fri, Dec 13, 2002 at 10:37:24AM -0800, Laurel Fan wrote:
> 
> I'm not sure exactly what you want to do, but if you want to do
> something to each line in a file, fgets() reads line by line. 
> 
> Or are you asking how to read input from a file in the first place?
> 
> -- 
> laurel at sdf.lonestar.org
> http://dreadnought.gorgorg.org
> On Fri, Dec 13, 2002 at 02:49:45PM -0500, KWMelvin wrote:

My first program created a sequential text file.  My next program
will read the sequential text file that was created, record by
record, formatting the output of each field, and sending that to stdout.

This may not have ANY use in the real world!  I certainly haven't been
able to find ANY examples in either my C textbooks (I have several on
my reference shelf), my C reference books (I have several on my shelf --
I did find the strtok() example in a reference book), or online.  Maybe
this is just an exercise that I want to do in order to learn about text 
files, arrays, strings, and/or pointers? I do think it is related to the
last few Beginner's Lessons, but _PCP_ is woefully lacking in examples
for doing this sort of thing. *I* seem to do much better with an example
to modify and play with, especially at this point in my C education. 
--
K

> > Okay, the fact that this works with a string array suggests a possible
> > solution: Somehow copy the file to a string array and make sure it ends
> > with a NULL.  Perhaps this string array could be called a "buffer"?
> > Then it might be possible to use strtok() with "\n" as the delimiter
> > to get a record?



More information about the Courses mailing list