地面之下高清百度网盘:C语言中?结构体方面的。谢谢

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 18:54:17
我刚接触到结构体,老师给了一个问题,有十个同学的学号,姓名、成绩。的一个结构体数组,要求用指针的方法,按照成绩排序。
谢谢了。

struct student
{
long id;
char name[10];
int chji;
}stu[10];

main()
{
struct student *p1,*p2;
struct student std;
for(int i=0;i<10;i++)
{ p1=&stu[i];
printf("请输入学号、姓名、成绩,用空格分开!");
scanf("%d",&p_stu->id);
scanf("%s",p_stu->name);
scanf("%d",&p_stu->chji);
}
for(i=0;i<9;i++)
for(j=1;j<10;j++)
{ p1=&stu[i];
p2=&stu[j]
if(p1->chji<p2->chji)
{ std=*p1;
p1=p2;
p1=&std;
}

}
}