Hi, I've been stuck with a buig for the last few days now, and just wondering if anyone could help me out with it.
Basically it's a fread problem, where fread seems to hit the end of file waay before it's supposed to. e.g. my file
is 56K, I'm reading 20 bytes from posion 364 and feof() is returning a value of 16.
I have a file which contains several arrays, all the code to load these arrays is set up and works as expected, as
I can load the first few elements of an array, I've also looked through the hex of the file to ensure that the data
is lined up in the file correctly. The problem I'm having is that random elements just don't seem to load at all.
for example, here is a loop in part of my code for loading up an array of GroupDesc objects. I'm loading it one element
at a time as it illustrates the bug better, but I'm getting the same behavior if I load all the objects as 1 elements thats
the size of the entire array, or if I load it as several elements that are their true sizes.
for (int i = 0; i < elementCount; ++i)
{
fseek(mFile, basePos + (sizeof(GroupDesc) * i), SEEK_SET);
Note that basePosition is always decimal 158, and sizeof(GroupDesc) is always decimal 20.
I have to explicitly seek to the position in file that I want to because for some, seemingly random reason, the stream
position indicator increments by more that 20 after reading element 1 (base zero) in the file. Here is the values of
the variables in the first three iterations of the loop (values are sampled at the end of the loop).
i = 0
position = 344
readAmount = 1
errorCode = 0
eofHit = 0
i = 1
position = 364
readAmount = 1
errorCode = 0
eofHit = 0
i = 2
position = 384
readAmount = 0
errorCode = 0
eofHit = 16
If you need any more info about the situation just let me know.
Also cheers for any help as I'm totally out of leads with this bug.
Just incase anyone else is suffering with the same problem, fread defaults to opening files in text mode, I'm guessing fread came across some values that read as eof for text files, which is why the bug seemed random.