0

Hello,
If I want to say compare a line at a given line number to another line at a different given line number how can I do this? I know I could iterate through the file and store the lines into a data structure and perform comparisons that way but the file is very large and was wondering how I could avoid that without taking up more memory? Or any other thoughts, thanks.

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
1

You don't have to store all the lines, just the two lines that you want to compare. Sequentially read the file, counting lines as you go along then save only the two lines you want to compare.

0

Thanks for the reply, I see. So I'm guessing there's not some simple built in function in the standard library or somewhere for it? If I want to avoid the lookup time as well I would have to make each line equal length and apply the offset to the file pointer it seems...

1

If all you want to do is run that program once when what' the point of making the text file into a fixed-length records? Such a scheme would limit the usefullness of your program.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.