I'm not sure if this is possible to do with qsort because what I want to sort (array of pointers to struct) is not what I am comparing (strings).
Here is an abridged version of my program (assume that all the student data is in core before we call qsort() and n is the number of records to sort):
struct student {
char lname[NAMESIZE + 1];
char fname[NAMESIZE + 1];
short mid;
short final;
short hmwks;
};
int cmp(const void *, const void *);
int
main(int argc, char **argv)
{
int n;
struct student *data[MAX];
qsort(data, n, sizeof(struct student *), cmp);
return 0;
}
int
cmp(const void *p0, const void *p1)
{
return strcmp((*(struct student *) p0).lname,
(*(struct student *) p1).lname);
}