I
Igal
hay, i'm having problem with my qsort function.
problem is with the sort, this sorts the array, but in wrong order,
when i go to debug and check value of
stu1->department or stu2->department
i see that it points ot garbage and not to the strings it should point
to.
i just can't figure out what's wrong.
typedef struct
{
unsigned long id;
char full_name[LEN];
char department[LEN];
struct
{
unsigned sem_a;
unsigned sem_b;
}Grades;
}Student;
....
Student **sptr = NULL; //this is array of pointers to Student (it's
not null when sort)
....
qsort(sptr, ARR_SIZE, sizeof(Student*), SortDepName);
....
int SortDepName(const void *e1, const void *e2)
{
Student *stu1 = (Student*)e1;
Student *stu2 = (Student*)e2;
if(strcmp(stu1->department, stu2->department) == 0)
{ return strcmp(stu1->full_name, stu2->full_name); }
else { return strcmp(stu1->department, stu2->department); }
}
problem is with the sort, this sorts the array, but in wrong order,
when i go to debug and check value of
stu1->department or stu2->department
i see that it points ot garbage and not to the strings it should point
to.
i just can't figure out what's wrong.
typedef struct
{
unsigned long id;
char full_name[LEN];
char department[LEN];
struct
{
unsigned sem_a;
unsigned sem_b;
}Grades;
}Student;
....
Student **sptr = NULL; //this is array of pointers to Student (it's
not null when sort)
....
qsort(sptr, ARR_SIZE, sizeof(Student*), SortDepName);
....
int SortDepName(const void *e1, const void *e2)
{
Student *stu1 = (Student*)e1;
Student *stu2 = (Student*)e2;
if(strcmp(stu1->department, stu2->department) == 0)
{ return strcmp(stu1->full_name, stu2->full_name); }
else { return strcmp(stu1->department, stu2->department); }
}