Segmentation Fault when printf string from a textfile
Hi! I have a struct
Code:
struct Human {
char *name;
int age;
};
I am trying to save and then read from textfile. I am doing this:
Code:
struct Human human= {"Carl",30};
printf("%s", human.name);
... Then I am saving it using
Code:
fwrite(&human, sizeof(Human), 1, outfile);
I am getting a resut as I am expecting and the printf works fine.
However, If I load from file using similar fread(). Then do the same printf, then I get the segmetation fault! Also This happens surely because of the string, not the integer, integers still gest outputted correctly if I get rid of string output.
Thank you!