请教各位大佬一个问题,为什么我每次输入第一个人的信息到了score那里就结束了???百思不得其解特地来论坛请教各位大佬
#include <stdio.h>
#include <malloc.h>
struct student
{
int age;
float score;
char name[100];
}; //结构体定义
int main(void)
{
int i, j;
int len;
struct student * pArr;
struct student t;
//动态构造一维数组
printf("请您输入学生总数:\n");
printf("len = ");
scanf_s("%d", &len);
pArr = (struct student * )malloc(len * sizeof(struct student)); //动态构造一维数组
//输入
for(i=0; i<len; ++i)
{
printf("请输入第%d个学生的信息:\n", i+1);
printf("age = ");
scanf_s("%d", &pArr[i].age);
printf("name = ");
scanf_s("%s", pArr[i].name);
printf("score = ");
scanf_s("%f", &pArr[i].score);
}
//将学生成绩升序输出 冒泡算法
for(i=0; i<len-1; ++i)
{
for(j=0; j<len-i-1; ++j)
{
if(pArr[j].score > pArr[j+1].score)
{
t = pArr[j] ;
pArr[j] = pArr[j+1];
pArr[j+1] = t;
}
}
}
printf("\n\n学生的信息是:\n");
//输出
for(i=0; i<len; ++i)
{
printf("第%d的学生的信息是:\n", i+1);
printf("age = %d\n", pArr[i].age);
printf("name = %s\n", pArr[i].name);
printf("score = %f\n", pArr[i].score);
printf("\n");
}
return 0;
}
运行结果如下:
javascript:; |