problem with qsort - Visual Studio

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); }
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
ScottChare

Latest Threads

Top