I have the following 2 structs:
typedef struct {
char fullName[40];
int yearOfBirth;
} Ancestor;
typedef struct {
Ancestor **ancestor;
int capacity;
int size;
} AncestorList;
and I would like to sort the Ancestor
elements os the array by yearOfBirth
. Here is how I call qsort():
qsort(listOfGreatUncles->ancestor, listOfGreatUncles->size, sizeof(Ancestor), compare); //listOfGreatUncles is a AncestorList struct
and here is my compare
procedure:
int compare(const void *s1, const void *s2) {
Ancestor *a1 = (Ancestor *)s1;
Ancestor *a2 = (Ancestor *)s2;
printf("a1 yearOfBirth %d\n", a1->yearOfBirth);
printf("a2 yearOfBirth %d\n", a2->yearOfBirth);
return (a1->yearOfBirth - a2->yearOfBirth);
}
}
Now my output for a1 and a2 are 0. What am I doing wrong?