标题:结构体成员排序问题
只看楼主
zm9456
Rank: 1
等 级:新手上路
帖 子:154
专家分:0
注 册:2007-4-30
 问题点数:0 回复次数:0 
结构体成员排序问题
#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);

}
有问题。。。。啊,请高手看看
搜索更多相关主题的帖子: maomao include 结构体 yishu 
2007-06-19 13:11



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-148674-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.118276 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved