how do I load a part of a file?

Started by
7 comments, last by delbogun 22 years, 6 months ago
I'm currently using these lines to open a file from disc:
  
OFSTRUCT file_data;
int file_handle = OpenFile(filename, &file_data, OF_READ);    
Now, I was wondering how do I open just a part of that file, example from byte 200 to byte 300. A example would be really appreciated. Edited by - delbogun on October 16, 2001 6:47:11 AM
Advertisement
You cant open just a part of a file, a files state is either opened or closed. Just open the file, and seek to the appropriate area, then read in the required amount of data.
-----------------------"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else's drivers, I assume it is their fault" - John Carmack
ok, thanks

but if you have a file that is example 200 mb, does it take long time to open the file and then seek the area?
Opening a file is just basically getting the filepointer to point to the file, the file is not actually placed in memory until YOU read from the file. Opening a 2kb file is the same as opening a 200Mb file.

djsomers
djsomers;)make it idiot proof and someone makes a better idiot!
thanks, i get it now
another question: how do I use _lseek?

example if I want to go to position 0x1A on a file, do I write this?

long pos = _lseek(file_handle,0x1A,SEEK_SET);

but then how do i use that information on _lread ?
MSDN doesn''t give me much information about that.
Just use lread on the file_handle after the call to lseek. That''s because lseek has already advanced the file_handle to position 0x1A
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
i tried that once, but it didn''t seem to work... i have probably missed something, thanks anyway, i''ll try again later with another file
Here is the code that reads file from byte 200 to byte 300

char buffer[100];
HFILE hFile = _lopen(filename, OF_READ);
_llseek(hFile, 200, FILE_BEGIN);
_lread(hFile, buffer, sizeof(buffer));

This topic is closed to new replies.

Advertisement