Reputation: 1669
I am new to C and I have this code:
f = fopen( argv[1], "rb" );
fseek( f, 64, SEEK_SET );
fpos_t pos;
fgetpos (f, &pos);
printf("%x", pos);
However, this returns 40, even though it's supposed to be returning 64. What am i doing wrong?
Upvotes: 0
Views: 323
Reputation: 215547
fpos_t
is not (necessarily) an arithmetic type and cannot be used with printf
. An implementation could even store it as a structure containing an encrypted position if it liked. Use ftell
(or ftello
if available) to get the file offset in a meaningful numeric form. fgetpos
is largely useless.
Upvotes: 1
Reputation: 5738
whatever you are printing is in hex format. 40 in decimal is 64. Do you mean the file size is 0x64 or 0x40
Upvotes: 1
Reputation: 3213
Because you're using %x. It's saying 40 as in 0x40, the hexadecimal number. You need %i or %d to get a decimal number.
Upvotes: 2
Reputation: 613461
You are outputting 64 in hex format, "%x"
. Since 64=0x40, the mystery is solved!
Upvotes: 4