• Advertisement

Archived

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

how do I load a part of a file?

This topic is 5943 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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));

Share this post


Link to post
Share on other sites

  • Advertisement