Change
char * name;
to
char name[MAX_NAME_LEN] ;
When you use sscanf
, name
must point to something. If you declare char *name
, name points nowhere.
and change
stage * s = malloc(sizeof(stage*));
to
stage * s = malloc(sizeof(stage));
You need the size of the structure stage
(sizeof(stage)
) and not the size of a pointer to stage
(sizeof(stage*)
). When you use sizeof(stage*)
, you dont allocate enough memory, then when you fill the newly allocated stage, you overwrite memory that does not belong to you and from then on you will get undefined behaviour (anything can happen).