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++: Boost interprocess memory mapped file error -

python - IO.UnsupportedOperation: Not Writable -

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