Archived

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

delbogun

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


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


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


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


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


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