If you want to write array of structures in file you should use loop to store each member. Coinsider this code:
#include <string.h>
#define LEN 5
typedef struct Test
{
int x;
double y;
}Test;
int main(void)
{
Test array[LEN];
Test res[LEN];
FILE* fp;
int i;
/*Open for writing*/
fp = fopen("test.bin","wb");
for (i = 0; i <LEN; i++)
{
array[i].x = i;
array[i].y = i * 2.5;
fwrite(&array[i], sizeof(Test), 1, fp);
}
fclose(fp);
/* Open for reading*/
fp = fopen("test.bin", "rb");
for (i = 0; i <LEN; i++)
{
fread(&res[i], sizeof(Test), 1, fp);
}
for (i = 0; i <LEN; i++)
{
printf ("%d %g\n", res[i].x, res[i].y);
}
fclose(fp);
return 0;
} Now, I think you'll know what to do...