Change your structure to
Code:
struct Human {
char name[30];
int age;
};
Pointers have to be dealt with separately when it comes to reading and writing to files.
Code:
struct Human {
char *name;
int age;
};
struct Human human= {"Carl",30};
// save
size_t len = strlen(human.name);
fwrite(&len, sizeof(len), 1, outfile); // the length of the name
fwrite(human.name, len, 1, outfile); // the name, excluding the \0
fwrite(&human.age, sizeof(human.age), 1, outfile); // the age
// load
size_t len;
fread(&len, sizeof(len), 1, infile); // the length of the name
human.name = malloc(len+1); // make space for the chars, and a \0
fread(human.name, len, 1, infile); // the name, excluding the \0
human.name[len] = '\0';
fread(&human.age, sizeof(human.age), 1, infile); // the age
Serialization - Wikipedia is the rabbit hole to go down if you want more.