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

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -