Simple reading
Hi!
I have here a stupit and easy(?) mistake in my source, but where?
FILE* pf;
pf = fopen("a file", "rb");
Now i want to jump at position 20 and read out a 22 big buffer.
char* buffer = 0;
unsigned int DataOffset = 20;
unsigned int Size = 22;
buffer = (char*) malloc (Size);
rewind (pf);
fseek (pf, DataOffset, SEEK_SET);
// read buffer
fread (buffer, 1, Size, pf);
And close it finally
flcose(pf);
The result is a 3 element big buffer, it should be 22 elements big, with the wrong stuff in it. Where could be the mistake?
Thanks, Christian
the rewind and fseek are redundant.
other than that,
#1, how do you figure its only reading 3 bytes?
#2, is the files bigger than 42 bytes?
#3, any cosmic ray activity in your area?
other than that,
#1, how do you figure its only reading 3 bytes?
#2, is the files bigger than 42 bytes?
#3, any cosmic ray activity in your area?
#1, how do you figure its only reading 3 bytes?
strlen(buffer) -> 3
#2, is the files bigger than 42 bytes?
yes. it is 58 bytes big.
#3, any cosmic ray activity in your area?
I dont know realy, but i think there is something with the mon.
strlen(buffer) -> 3
#2, is the files bigger than 42 bytes?
yes. it is 58 bytes big.
#3, any cosmic ray activity in your area?
I dont know realy, but i think there is something with the mon.
You are reading a binary file (at least that''s how you''re opening the file). You can''t count bytes read with strlen because at the first ''\0'' it will stop counting and return the result. In this case the 4th byte probably is ''\0'' and strlen returns STRING length 3.
So the moon is probably ok even there.
- Benny -
So the moon is probably ok even there.
- Benny -
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement