typedef
struct zoz
{
int age;
int mag;
int suly;
}
nevsor_t;
int olvas(nevsor_t * pnevsor)
{
return scanf("%d %d %d",
&pnevsor->age, &pnevsor->mag, &pnevsor->suly);
}
int kiir(nevsor_t nevsor)
{
return printf("%d year\t%d cm\t%d kg\n",
nevsor.age, nevsor.mag, nevsor.suly);
}
int sort_age(const void *a, const void *b)
{
struct nevsor_t *ia = (struct nevsor_t *)a;
struct nevsor_t *ib = (struct nevsor_t *)b;
return *ia->age - *ib->age;
}
I want to sort the elements of block tomb by age which is the first variable of struct nevsor_t.
The elements are added manually from the keyboard:
int main()
{
int i,n;
nevsor_t tomb[50];
nevsor_t t;
printf("Add meg a resztvevok szamat:");
scanf("%d", &n);
printf("\n");
for (i=1;i<=n;i++) {
printf("%2d. resztvevo adatai: ", i);
olvas(&t);
tomb[i]=t;
}
qsort(tomb, n, sizeof (tomb[0]), sort_age);
for (i=1;i<=n;i++) {
printf("%d. : ",i);
kiir(tomb[i]);
}
return 0;
}
And the problem is with this line:
return *ia->age - *ib->age;
"ia" and "ib"---pointer to incomplete class type is not allowed.
Any ideas how could I fix this kind of problem?