fread() behaves weird

Posted by Cres on Stack Overflow See other posts from Stack Overflow or by Cres
Published on 2010-03-27T18:27:07Z Indexed on 2010/03/27 18:33 UTC
Read the original article Hit count: 267

Filed under:
|

hi, I have a problem in a C program of mine where after I use fread(), the file pointer goes to the end of the file sometimes.

I'll try to explain better - the code looks something like:

dummy = ftell(fp);
fread(&buf, sizeof(unsigned char), 8, fp);
dummy = ftell(fp);

where fp is a file pointer to an opened file (opened it with "w+", I'm using it as a binary file and I know i'm supposed to have a "b" in there too, but I heard its not really important to add it..), dummy is just an unsigned long variable, and buf is unsigned char[8]

now, when debugging, at the ftell before the fread, dummy is 262062 at the ftell after the fread, dummy is 262640 even though I only 'moved' 8 bytes..

does anyone have any idea what can be the cause of this..? thanks for your help :)

© Stack Overflow or respective owner

Related posts about c

    Related posts about fread