【发布时间】:2010-12-20 20:42:47
【问题描述】:
我正在对一堆 IP 进行排序,但由于某种原因,它们的顺序错误。我不太确定问题出在哪里。
66.249.71.3
190.148.164.245
207.46.232.182
190.148.164.245
190.148.164.245
202.154.114.253
190.148.164.245
190.148.164.245
66.249.71.3
190.148.164.245
202.154.114.253
这是我对它们进行排序的方式。
typedef struct {
char *ip;
} mystruct;
/* qsort */
int struct_cmp(const void *a, const void *b)
{
mystruct *ia = (mystruct *)a;
mystruct *ib = (mystruct *)b;
return strcmp(ia->ip, ib->ip);
}
...
qsort(a_struct, 11, sizeof(mystruct*), struct_cmp);
for(..){
printf("%s\n",a_struct[i]->ip);
}
任何帮助将不胜感激。谢谢
【问题讨论】:
-
你给出的是输入还是输出的样本?