Link to home
Start Free TrialLog in
Avatar of jhshukla
jhshuklaFlag for United States of America

asked on

offset while reading file

I am trying to read something from a bitmap and want to read the info at particular offset from the beginning of file. how can i do that?
I tried this but doesn't seem to work:

FILE *f = fopen("filename");
fread(&somestruct, 1, bytes_to_read, f+someOffset);

is there something similar to seekp() (C++)

thx
jay
ASKER CERTIFIED SOLUTION
Avatar of sneeuw_chan
sneeuw_chan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jhshukla

ASKER

could you explain the meanings of SET, CUR and END? As far as I remember
SET sets the pointer at the offset,
CUR displaces the pointer from the current position by offset bytes
END makes it point at offset bytes (backwards) from the END
Avatar of sneeuw_chan
sneeuw_chan

Almost.  END makes it point at offset bytes _forwards_ from the end.  Remember, the offset is signed, so it can be negative.
The rest is as you stated, SET is relative to the start of the file, and CUR is relative to the current position.
do you mean fseek(somefile, +10, SEEK_END) would make is point to ten bytes beyond the EOF? that is a bad thing!
Yup, 10 bytes beyond the EOF.  Why would that be a bad thing ?
not if we know what we are doing. thx.