【发布时间】:2014-02-13 05:17:43
【问题描述】:
所以我为 qsort 定义了函数比较,但显示以下错误:
1.c: In function ‘compare’:
1.c:235:7: error: request for member ‘count’ in something not a structure or union
1.c:235:17: error: request for member ‘count’ in something not a structure or union
1.c:237:12: error: request for member ‘count’ in something not a structure or union
1.c:237:23: error: request for member ‘count’ in something not a structure or union
有人知道为什么吗?我的意思是这不是我拼错了名字:
struct word
{
char wordy[100];
int count;
};
int compare(const void* a, const void* b)
{
const struct word *ia = (const struct word *)a;
const struct word *ib = (const struct word *)b;
if(*ia.count>*ib.count)
return 1;
else if(*ia.count==*ib.count)
return 0;
else
return -1;
}
【问题讨论】:
-
现在,您已经编辑了原始帖子以修复拼写错误。将来,复制/粘贴真实来源 - 不是您最好的回忆。
-
建议同时显示您的
qsort()电话。根据您要排序的内容,比较功能可能会有其他问题。 -
更改为
(*ia).count或ia->count -
rjv答错了。