C语言问题,为什么我的第一个for循环只能执行一次,然后直接跳到return了?

2020-04-30 教育 88阅读
# include
# include
struct student
{
int age;
double score;
char name[30];
};
int main(void)
{
struct student * p, t;
int len, i, j;
printf("输入学生个数:");
printf("len=");
scanf_s("%d", &len);
p = (struct student *)malloc(len * sizeof(struct student));
for (i = 0; i < len; ++i)
{
printf("输入第%d学生的信息:\n", i+1);
printf("输入学生年龄:");
scanf_s("%d", &p[i].age);
printf("输入学生成绩:");
scanf_s("%lf", &p[i].score);
printf("输入学生姓名:");
scanf_s("%s", (p + i)->name);
}
printf("\n\n");
for (i = 0; i < len - 1; ++i)
{
for (j = 0; j < len - 1 - i;++j)
if (p[j].score > p[j + 1].score)
{
t = p[j];
p[j] = p[j + 1];
p[j + 1] = t;
}
}
for (i = 0; i < len; ++i)
{
printf("第%d个学生的信息是:\n\n", i+1);
printf("年纪是%d\n\n", p[i].age);
printf("分数是%lf\n\n", p[i].score);
printf("姓名是%s\n\n\n\n", p[i].name);
}
return 0;
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com