Вы можете создать функции save
и load
:
void save(Frame frame){
FILE *file = fopen("/path/to/save.txt", "w");
if(file != NULL){
fwrite(&frame, sizeof(Frame), 1, file);
fclose(file);
}
else
printf("Error %d\n", errno);
}
Frame load(void){
Frame frame;
FILE *file = fopen("path/to/save.txt", "r");
if(file != NULL){
fread(&frame, sizeof(Frame), 1, file);
fclose(file);
}
else
printf("Error %d\n", errno);
return frame;
}
А затем в вашей функции main
:
int main(void){
Frame f = {
.name = "my_frame",
.duration = 60,
.path = "/path/to/frame"
};
save(f);
Frame g = load(); // It will load f to g
printf("%s %d %s\n", g.name, g.duration, g.path);
return 0;
}