2016-01-16 52 views
0

我试图结构数组上使用qsort,但我得到这个错误:之前预期主表达式“*”令牌与数组结构的qsort?

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); 
+4

提供正确的转换符:'(muchie *)' –

+2

只要使用'的std :: sort',这就是它是。 –

回答

1

参数的铸造是错误的 - 应该是*(muchie*)p而不是*(muchie* p)

用途:

int cmp(const void* p, const void* q) 
{ 
    muchie vp,vq; 
    vp=*(muchie*) p; 
    vq=*(muchie*) q; 
    return vp.c-vq.c; 
} 
+0

哦,男孩!非常感谢您指出了这一点!我一直在盯着屏幕一会儿! –

+0

@rptoma - 没问题,很乐意帮忙。 –