struct student { int i; char name[10]; int chinese , math, english; }; int main(void) { int x, y; struct student stu; printf("input y:"); scanf("%d", y); printf("input the student's number,name and courage scores\n"); for (x = 1; x <= y; x++) { printf("No.%d:", x); scanf("%d%s%d%d%d", &stu.i, &stu.name, &stu.math, &stu.english, &stu.chinese); } printf("i:%d,name:%s,\n",stu.i,stu.name ); return 0; }
时间: 2023-10-13 18:04:19 浏览: 105
这段代码存在一些问题:
1. 在第6行中,应该使用取地址符&获取变量y的地址,即应该为scanf("%d", &y)。
2. 在第12行中,应该使用取地址符&获取结构体成员变量的地址,即应该为scanf("%d%s%d%d%d", &stu.i, stu.name, &stu.math, &stu.english, &stu.chinese)。
3. 在第14行中,应该输出循环中每个学生的成绩信息,而不是最后一个学生的信息。可以将printf语句放在循环中。
修改后的代码如下:
```
struct student {
int i;
char name[10];
int chinese, math, english;
};
int main(void) {
int x, y;
struct student stu;
printf("input y:");
scanf("%d", &y);
printf("input the student's number, name and course scores\n");
for (x = 1; x <= y; x++) {
printf("No.%d:", x);
scanf("%d%s%d%d%d", &stu.i, stu.name, &stu.math, &stu.english, &stu.chinese);
printf("No.%d: i:%d, name:%s, math:%d, english:%d, chinese:%d\n", x, stu.i, stu.name, stu.math, stu.english, stu.chinese);
}
return 0;
}
```
阅读全文
相关推荐

















