It's easy to write and read a structure from a file. Here are some examples.
Code:
#include <stdio.h>
typedef struct{
int data;
} MYSTRUCT;
void ReadData(char *file, MYSTRUCT *pstruc){
FILE *f=fopen(file,"rb");
fread(pstruc,sizeof(MYSTRUCT),1,f);
fclose(f);
}
void SaveData(MYSTRUCT *pstruc, char *file){
FILE *f=fopen(file,"wb");
fwrite(pstruc,sizeof(MYSTRUCT),1,f);
fclose(f);
}
int main(){
MYSTRUCT ms;
ms.data=1;
SaveData(&ms,"mystruct.dat");
ms.data=0; // zeroed to test reading function
ReadData("mystruct.dat",&ms);
printf("MyStruct's Data = %d\n",ms.data); // should be 1
return 0;
}