HOWTO: Read a LARGE file, line by line backwards??

  • Thread starter Thread starter tor
  • Start date Start date
T

tor

Hi
I need to find the last occurrence of a string in a textfile.
I don't want to read from the start of the file because its
huge 60+Mb.

Torfinn
 
1. Open the file -- CreateFile(...)
2. Move to its end -- SetFilePointer(...)
allocate buffer of size N
while (position - N > 0)
{
move N chars to the top
read N chars into the buffer
search for the string in the buffer (within the X actually read chars)
if (string found)
break;
}

Got it?:)
Cheers,
Stoyan
 
Back
Top