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++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -