Hi. I have to create a genealogy list reading a file with the following input:
10/10/1983,Tom,Mark,Julia
...
...
11/02/1993,Tim,Sam,Jenny
I have X strings in the file, every string contains a date, the person name, then the name of the father and the name of the mother.
I'm creating a list of persons, reading the input file.
Code:
typedef struct {
char date[MAX_PATH];
char nameSurname[MAX_PATH];
struct person * father;
struct person * mother;
} person;
typedef struct list {
person * aPerson;
struct list * next;
} peopleList;
peopleList * head = NULL;
void addPerson(person * thePerson){
peopleList * tmp = (peopleList *)malloc(sizeof(peopleList));
tmp->aPerson = thePerson;
tmp->next = head;
head = tmp;
}
void createPerson(char * aDate, char * aName, char * aFather, char * aMother){
person * tmp;
tmp = (person *)malloc(sizeof(person));
strcpy(tmp->date, aDate);
strcpy(tmp->nameSurname, aName);
// HERE I SHOULD GET THE POINTERS TO THE FATHER AND MOTHER (IF ANY.. NULL OTHERWISE)
addPerson(tmp);
}
The problem is that when I want to create a person (while tokenizing the input) before inserting it, I have to look in the previously created person list If I already know the mother and the father of the person I'm creating and I don't know how to get the pointer to them that I will put in the person structure I'm creating.