Your PersonType
struct contains a pointer to a string that you are never allocating, nor assigning. So fname
is an uninitialized pointer that you are attempting to write to. You need to allocate a buffer for fname
.
int main() {
PersonType *p;
p = (PersonType *)malloc(sizeof(PersonType));
p->fname = malloc(sizeof(char)*7);
char * name = "Robert";
Either that or make fname
a char
array so that your struct will contain a buffer within itself.