[求教]qsort对结构体二级排序,程序不能运行?
#include <stdio.h> #include <stdlib.h>
void main()
{
struct In
{
int x;
int y;
}s[10];
int cmp( const void *a , const void *b )
{
struct In *c = (In *)a;
struct In *d = (In *)b;
if(c->x != d->x) return c->x - d->x;
else return d->y - c->y;
}
int i,j;
for(i = 0; i< 10; i++)
scanf("%d%d ", &s[i].x,&s[i].y);
qsort(s,10,sizeof(s[0]),cmp);
for(i = 0; i< 10; i++)
printf("%d%d ", s[i].x,s[i].y);
printf("\n");
}
[此贴子已经被作者于2017-1-31 15:36编辑过]