带有结构数组的 qsort
qsort with array of structs?
我正在尝试在结构数组上使用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);
参数的转换是错误的 - 应该*(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;
}
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- 将数组的地址分配给变量并删除
- 从C++本机插件更新Vector3数组
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 数组索引的值没有增加
- 将对象数组的引用传递给函数
- 为char数组调整zlib-zpipe
- 使用 Qt qSort() 在数组上调用 qSort
- 为什么在此代码中,C++中的排序比 C 中的 qsort 慢得多(对于字符串数组)
- 1索引数组上的qsort()正在扰乱索引
- 在结构数组上C++ qsort 内部函数
- 带有结构数组的 qsort
- 在Qsort、c或c++中使用一个记录数组
- Qsort不工作-把数组完全搞乱了
- 用qsort -正确的类型转换排序2D数组
- 如何在c++中使用qsort对字符串数组进行排序
- c++中用于字符串数组的qsort
- Qsort不会对整型数组进行任何更改
- Qsort 无法正确排序字符串数组