Pregunta

I want to read bytes from a file with a certain offset.

I have to do the same thing in VB6 and from C++.

For example like that:

FILE *file =fopen(szFileName,"rb");
fseek( file, iFirstByteToRead, SEEK_SET);
fread(nBytes,sizeof(unsigned char), iLenCompressedBytes, file);

(yes, I know nBytes is not declared as byte, but I named it nBytes anyway to keep my VB6 naming).

In VB6 I have to use

Get #iFile, iFirstByteToRead, nBytes

In VB6, the first byte (when using "Get") is on position 1. This means I would have to say

Get #iFile, 1, nBytes

... to read the bytes from the very beginning of a file.

I would like to know if fseek is also 1-based or if it is 0-based.

Would I have to diminish iFirstByteToRead by -1 to get the same results?

My question is of pure theoretical nature, please don't say that my coding is bad or so...

Thank you.

¿Fue útil?

Solución

In short terms: fseek offsets for a SEEK_SET are zero-based (e.g. fseek(your_file, 0, SEEK_SET) will set the stream position to the beginning).

Otros consejos

The first byte is at offset 0 in the file.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top