主题:为什么我的程序提前跳出循环
#include<stdio.h>
#include<malloc.h>
struct Student
{
int age;
float score;
char name[100];
};
int main(void)
{
int len;
int i;
struct Student *pArr;
printf("Çëêäèëѧéúμĸöêy£o\n");
printf("len = ");
scanf("%d", &len);
pArr = (struct Student *)malloc(len * sizeof(struct Student));
for(i = 0; i < len; ++i)
{
printf("Çëêäèëμú%d¸öѧéúDÅÏ¢", i+1);
printf("age = ");
scanf("%d",&pArr[i].age);
printf("score = ");
scanf("%f", &pArr[i].score);
printf("name = ");
scanf("%s",pArr[i].name);
}
return 0;
}
在windows7 32位运行结果如下:
请输入学生的个数:
len = 3
请输入第1个学生信息age = 1
score = 2
name = 3
请输入第2个学生信息age = 1
score = 2
name = 3
请输入第3个学生信息age = score = name = 请按任意键继续. . .
我想提问,为什么第三个学生信息不能输入????
#include<malloc.h>
struct Student
{
int age;
float score;
char name[100];
};
int main(void)
{
int len;
int i;
struct Student *pArr;
printf("Çëêäèëѧéúμĸöêy£o\n");
printf("len = ");
scanf("%d", &len);
pArr = (struct Student *)malloc(len * sizeof(struct Student));
for(i = 0; i < len; ++i)
{
printf("Çëêäèëμú%d¸öѧéúDÅÏ¢", i+1);
printf("age = ");
scanf("%d",&pArr[i].age);
printf("score = ");
scanf("%f", &pArr[i].score);
printf("name = ");
scanf("%s",pArr[i].name);
}
return 0;
}
在windows7 32位运行结果如下:
请输入学生的个数:
len = 3
请输入第1个学生信息age = 1
score = 2
name = 3
请输入第2个学生信息age = 1
score = 2
name = 3
请输入第3个学生信息age = score = name = 请按任意键继续. . .
我想提问,为什么第三个学生信息不能输入????