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

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -