回复 9楼 ileelsai
按照你那样改行了,问一下为什么我那样不行啊
#include<stdio.h> #include<malloc.h> struct Student { char name[100]; int age; float score; }; int main(void) { int len; int i,j; struct Student st; struct Student *p; printf("请输入一共有几位学生:"); scanf("%d",&len); p=(struct Student *)malloc(len*sizeof(struct Student)); //输入 for(i=0;i<len;++i) { printf("请输入第%d位同学的信息:\n",i+1); printf("name:"); scanf("%s",&(p+i)->name); printf("age:"); scanf("%d",&p[i].age); printf("score:"); scanf("%f",&p[i].score); } //按成绩进行排序 //冒泡排序 for(i=0;i<len-1;++i) { for(j=0;j<len-i-1;++j) { if(p[j].score<p[j+1].score) { st=p[j]; p[j]=p[j+1]; p[j+1]=st; } } } printf("\n\n"); printf("学生的信息如下\n"); //输出 for(i=0;i<len;++i) { printf("请输出第%d位同学的信息:\n",i+1); printf("name:%s\n",p[i].name); printf("age:%d\n",p[i].age); printf("score:%f\n",p[i].score); } return 0; }