Date: Wed, 29 Oct 1997 17:38:50 -0800 (PST) Message-Id: <199710300138.RAA10772@adit.ap.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: jb AT netcom DOT ca, djgpp AT delorie DOT com From: Nate Eldredge Subject: Re: Using data from file, line by line using C? Precedence: bulk At 11:19 10/28/1997 -0500, jb AT netcom DOT ca wrote: >Hi, > >I was wondering if anyone knows what kind of code is required to do the >following. > >e.g. You have a file in the home directory of the program with >customers' names. (one name per line) > >You want the program to bring up each persons' name one by one, and give >the option to write the persons' name with a variable to a file, say >maybe into chart form. >So that the output would be something like this: > > >Name 1| Variable 1 >Name 2| Variable 2 >Name 3| Variable 3 >Name 4| Variable 4 >Name 5| Variable 5 >Name 6| Variable 6 >.... > >and next time you run the program and it brings up the name, you want it >to tack on another column to the chart, with a different variable. Offhand, I would say you'd do something like this: - Read a line (using fgets() or equivalent) - Get the data you need, like the name (using sscanf or string functions to parse) - Write out the line to a new file, ommiting the \n - Write the new data, followed by \n - Repeat... - Use unlink() and rename() to move the new file over the old one. HTH Nate Eldredge eldredge AT ap DOT net