结构体成员排序问题
#include "stdio.h"main()
{
struct student
{char name[20];
int num;
char sex;
char acad[10];
};
struct student stu[4]={{"feiming",102,'m',"xingxi"},
{"tuxianjian",101,'m',"xingxi"},
{"xiaoping",103,'f',"yishu"},
{"maomao",100,'f',"jixie"}};
struct student *p;
int i,j,k;
struct student *temp;
for(p=stu,i=0;p<stu+3;p++,i++)
{ k=i;
for(j=i+1;j<4;j++)
if((p->num)>(p+1)->num)
k=j;
if(k!=i)
{temp=(p+i);(p+i)=(p+k);(p+k)=temp;}
}
printf("N0. name sex acad\n");
for(p=stu;p<stu+4;p++)
printf("%-10s%5d%2c%-4s\n",p->name,p->num,p->sex,p->acad);
}
有问题。。。。啊,请高手看看