#### Archived

This topic is now archived and is closed to further replies.

# how do I load a part of a file?

## Recommended Posts

delbogun    122
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

##### Share on other sites
Maximus    124
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.

##### Share on other sites
delbogun    122
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?

##### Share on other sites
djsomers    123
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

##### Share on other sites
delbogun    122
thanks, i get it now

##### Share on other sites
delbogun    122
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.

##### Share on other sites
NuffSaid    122
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

##### Share on other sites
delbogun    122
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

##### Share on other sites
Guest Anonymous Poster
Here is the code that reads file from byte 200 to byte 300

char buffer[100];