Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!ucla-cs!rutgers!gatech!prism!nsfacgs From: nsfacgs@prism.gatech.EDU (Gary Smith) Newsgroups: comp.lang.c Subject: Sorting Structures Message-ID: <30365@hydra.gatech.EDU> Date: 1 Jun 91 21:44:27 GMT Distribution: usa Organization: Georgia Institute of Technology Lines: 65 Can someone explain why this sort will not work under BC++. Thanks. ------Snip-------- #include #include #include struct personel { char name[30]; int age; } employee[5]; int my_sort(struct personel *s, struct personel *d); main() { int x; strcpy(employee[0].name, "John Doe"); employee[0].age = 30; strcpy(employee[1].name, "Jane Doe"); employee[1].age = 28; strcpy(employee[2].name, "Joanne Doe"); employee[2].age = 5; strcpy(employee[3].name, "Jimmy Doe"); employee[3].age = 12; strcpy(employee[4].name, "Josh Doe"); employee[4].age = 8; for ( x=0; x<5; x++ ) printf("NAME: %s AGE: %d\n", employee[x].name, employee[x].age); printf("\n\n"); qsort(employee, 5, sizeof (struct personel), my_sort); for ( x=0; x<5; x++ ) printf("NAME: %s AGE: %d\n", employee[x].name, employee[x].age); return(0); } /* Normally this function will return the opposite (-1 or 1) but since we want this to be in DECENDING order, you have to do it this way */ int my_sort(struct personel *s, struct personel *d) { if ( s->age < d->age ) return(1); if ( s->age > d->age ) return(-1); return(0); } -------End Snip--------