0

I have a binary file in which 64 bits blocks are a number that I need. If I try to read it with:

FILE *ptr;
ptr = fopen("HH", "rb"); //r for read, b for binary
ulong val;
fseek(ptr, 0, SEEK_SET);
fread(&val, 8, 1, ptr);

it doesn't work (it gives random values always different), but it work if I say him to acquire until 3 bytes (in the sense that I have the right value for that three bytes - with little ending encoding, that is the right one). I've also tried with char type, it put the right value of each byte in each element of my char array, but then I don't know how to cast it into a long int type (I've managed just to do it element per element, but is not what I need). Can you help me? Thanks!

domx
  • 13
  • 1

1 Answers1

0

I've understood the mistake! It was just a problem with printf, the data was acquired well. I said:

printf ("%d", val);

instead of

printf ("%ld", val);

where the ld is for long type...

domx
  • 13
  • 1