dear all, I am sorry, I have just started to use C.
I have a strange thing here and would appreciate if someone can explain why this working as it is. If I uncomment one of the memcpy's, the 2nd printf changes. I'd expect that it only changes once I uncomment the last memcpy.
(The solution might be a different way and I'd more then happy if someone can point me to the right direction. I want to have a double example 25 written in binary form and right order in a file for example as 40390000)
But now to my problem:
Code:
#include <stdio.h>
#include <string.h>
int main()
{
FILE *flat;
double fl=1280,*ptr;
int flr=0,b;
flat = fopen ("floats.txt","wb+");
ptr=&fl;
memcpy(&flr,&fl,8); // comment this out, flr changes, why?
memcpy(&flr,&ptr[0],4);
printf("x:%X %p\n",flr,&flr);
b=(flr&0xff000000)>>24 | (flr&0xff0000)>>8 | (flr&0xff00)<<8 | (flr&0xff)<<24;
fwrite(&b,4,1,flat);
fclose(flat);
printf("done\n");
return 0;
}
Thanks
D