Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving around in files...

Status
Not open for further replies.

gonzilla

Programmer
Apr 10, 2001
125
0
0
US
Hi,

I have a large file with blocks of text starting with an "l ". I have to find the begining (strncmp), read the rest of the block and write the output file with the same info with an addition or two. As an example, if input looks like this:

l compfl
ttlFlags for where we are/were in the interview
n10Base
n01not yet qualified; c=c145'1'
n01Qualified; c=c145'2'

The output would look like this:

l compfl;c=c145u$ $
ttlFlags for where we are/were in the interview
n10Base
n01not yet qualified; c=c145'1'
n01Qualified; c=c145'2'

There are other formats of the block. And there is always a blank line between blocks in the input.

My question is, how do I read a line and after finding "l ", read some more input until the the next block then write the output with the results getting back and forth with ease? Do I write the output first and alter it or just work a line at a time writting the output as I go? Also, any help with finding the arbitrary number within the string and changing it to an integer would be of great help. (The number can be 3 or 4 digits long)

Thanks for your help. (Sorry about the semi-long post)

-Tyler
 
while(x != EOF)
{
x = fgetch(yourfile);
putc(x);
} Ion Filipski
1c.bmp


filipski@excite.com
 
I think you can try a combination between fgets to read a line from your source file, alter the line as your wish and after that use puts to write the line in your destination file.
Hope it will help
 
Hi,

Thanks. I was actually able to work it all out without much help. I used fgets and fputs. The problem wasn't what function I used to write the file, but more how to find something, read some more and return to the spot that I found what I was looking for and finally write the results with the new information I found. I just used ftell and fseek for this.

Thanks.

-Tyler

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top