Tout ça marche très bien :
#include <stdio.h>
struct HIT
{
float x;
float y;
float z;
};
void main()
{
HIT hit = { 1.5 , 2.7 , -3.9 };
void* buffer = &hit;
int size = sizeof(HIT);
// plus loin dans le programme
FILE* pFile = fopen("C:/Temp/test.dat","wb");
if (pFile)
{
printf("Ecrire hit : x=%f y=%f z=%f\n",hit.x,hit.y,hit.z);
fwrite(buffer,size,1,pFile);
fclose(pFile);
}
// encore plus loin dans le programme
HIT hit2;
pFile = fopen("C:/Temp/test.dat","rb");
if (pFile)
{
fread(&hit2,size,1,pFile);
fclose(pFile);
printf("Lire hit2 : x=%f y=%f z=%f\n",hit2.x,hit2.y,hit2.z);
}
}
ce qui donne :
Ecrire hit : x=1.500000 y=2.700000 z=-3.900000
Lire hit2 : x=1.500000 y=2.700000 z=-3.900000
Jean-François