I have a new typedef struct and an init function for it.
#include <stdlib.h>
#include <stdio.h>
typedef struct PERSON
{
char * name;
char * surname;
int month;
int day;
} * Person;
Person init_person(char * name, char * surname, int month, int day)
{
Person person = calloc(1, sizeof(Person));
person->name = name;
person->surname = surname;
person->month = month;
person->day = day;
return person;
}
int main(int argc, char * argv[])
{
Person person = init_person("Hello", "World", 12, 12);
printf("\n%s\n", person->name);
printf("\n %i %i \n", person->month, person->day);
return 0;
}
When the code is run, the expected output should be:
Hello
12 12
But instead, I am getting:
Hello
0 1769108595
When I swap around the printf
function statements, I do get the desired output. I have written similar code using structures before but I have not faced such a problem. Could it be a memory problem?