c++ - qsort with array of structs? -
i trying use qsort
on array of structs 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);
the casting of parameters wrong - should *(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; }
Comments
Post a Comment