Reputation: 2262
I am trying to use qsort
on an array of structs but I get this error: expected primary-expression before '*' token
struct muchie {
int x,y,c;
} a[100];
int cmp(const void* p, const void* q)
{
muchie vp,vq;
vp=*(muchie* p);
vq=*(muchie* q);
return vp.c-vq.c;
}
// ....
qsort(a,m,sizeof(muchie),cmp);
Upvotes: 0
Views: 1033
Reputation: 11406
The casting of the parameters is wrong - should be *(muchie*)p
instead of *(muchie* p)
.
Use:
int cmp(const void* p, const void* q)
{
muchie vp,vq;
vp=*(muchie*) p;
vq=*(muchie*) q;
return vp.c-vq.c;
}
Upvotes: 1