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.

Recommended Answers

All 3 Replies

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.

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...

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.