jhshukla
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
The rest is as you stated, SET is relative to the start of the file, and CUR is relative to the current position.
ASKER
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 ?
ASKER
not if we know what we are doing. thx.
ASKER
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