#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char* file_name = "G:\\aaaa.xyz";
struct Car {
char maker[32];
int price;
};
struct owner {
char name[32];
int age;
Car* car;
};
void save() {
owner op ;
strcpy(op.name,"xiaoming");
op.age = 20;
Car* mycar=(Car*)malloc(sizeof(Car));
strcpy(mycar->maker, "BMW");
mycar->price = 20;
op.car = mycar;
FILE* fw = fopen(file_name, "wb");
fwrite(op.name, 1, 32,fw);
fwrite(&op.age, 1, 4, fw);
fwrite(op.car->maker, 1, 32, fw);
fwrite(&op.car->price, 1, 4, fw);
fclose(fw);
}
void load() {
FILE* fr = fopen(file_name,"rb");
char name[32];
fread(name, 1, 32, fr);
printf("%s\n", name);
int age;
fread(&age, 1, 4, fr);
printf("%d\n", age);
}
int main() {
save();
load();
}