in reply to Backwards searching

How large your file is affects the options you have. If the file is less than a few hundred kilobytes, it might be easiest to load the file into memory and treat it like an array.

If your file is larger, but static, you may want to build a series of indexes that represent the byte offset of the start of each line. If the file changes with any about of frequency, however, this option would probably not be so good.

The problem is that reading backwards in a file on a line by line basis is not a "natural" thing for most (if any) operating systems to do. Most operating systems support fairly efficient methods of moving of the file pointer around, but have no concept of "lines". Lines are an arbitrary construct, and are dependant on what you call your end of line character (typically a linefeed (unix), or carriage return/linefeed (DOS/Windows), or someother character of the user's choosing.

While there isn't any code in this example to tell you how to do it, maybe it'll give you some ideas about how to manage the data.

--Chris

Update: Or better yet, use btrotts solution.

Replies are listed 'Best First'.
RE: Thanks
by JPC (Initiate) on Jun 14, 2000 at 01:15 UTC
    Thanks guys for the quick response. I oversimplified by using the term "lines." If there is a way to read bytes from a file pointer position backwards--that would be a great help. If not, I do have some work-arounds I can use, but I'd like to know if it's possible.