If someone can write me how to read with fscanf function value from the binary file, if it is unsigned short. An example. please. I urgently need that. I know how to do that in matlab, but c++ is a little different. it probably look at this way:
FILE* f = fopen("example.bin", "rb");
fseek(f, a_place_in_bin_file, SEEK_END);
unsigned short usNumber;
fscanf(f, "%u", &usNumber);
printf("%u", usNumber);
but somewhere is a mistake, I do not know how to properly declare the variable and type of data to read. I hope you understand me..thanks..
I still have a problem with reading data. I can not believe some data type works, some will not. I searched the internet and I don't know where is the mistake and why I get some stupid values..huge values. this is my code:
1 2 3 4 5 6 7 8
rewind (f);
fseek(f,iPos[0],SEEK_SET);
unsignedshort foo;
fread(&foo,1,sizeof(foo),f);
printf("%d\n",foo); /*this code does not work I get a 4110 instead of 3600*/
unsignedchar foo1;
fread(&foo1,1,sizeof(foo1),f);
printf("%u\n",foo1);/* this code works fine*/
where is mistake? endian?
My code only works for unsigned char type, for any other type of data i get some stupid values..i need this quickly please..thanks..