|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 爱学习520 于 2020-6-30 09:08 编辑
为什么我这个程序到 输入第二个学生学号 的时候直接跳过了,根本无法输入第二个学生的学号,如图 :
昨天到今天都没有找出来的错误,请求大佬
- /*
- * 有10个学生
- * 每个学生的数据包括学号、姓名、3门课的成绩
- * 从键盘输入10个学生数据
- * 要求分别输出
- * 3门课程的平均成绩
- * 总分最高的学生的数据(包括学号、姓名、3门课程成绩、平均分数)
- */
- #include<stdio.h>
- #include<stdlib.h>
- struct student{
- char sno[20];
- char name[20];
- int score[3];
- };
- main()
- {
- int i;
- struct student * stu[2];
- //申请2块学生类数据
- for(i=0;i<2;i++)
- stu[i]=(struct student *)malloc(sizeof(struct student));
- //输入数据
- for(i=0;i<2;i++)
- {
- printf("--------请输入第%d个学生信息的学号、姓名、三科对应分数--------\n",i+1);
-
- printf("请输入第%d个学生的学号:",i+1) ;
- gets(stu[i]->sno);//输入学号
-
- printf("\n");
-
- printf("请输入第%d个学生的姓名:",i+1) ;
- gets(stu[i]->name);//输入姓名
-
- printf("\n");
-
- printf("请输入第%d个学生的三科对应成绩:",i+1) ;
- scanf("%d %d %d",&stu[i]->score[0],&stu[i]->score[1],&stu[i]->score[2]); //输入分别对应成绩
-
- printf("\n");
-
- }
- }
复制代码
试试: - /*
- * 有10个学生
- * 每个学生的数据包括学号、姓名、3门课的成绩
- * 从键盘输入10个学生数据
- * 要求分别输出
- * 3门课程的平均成绩
- * 总分最高的学生的数据(包括学号、姓名、3门课程成绩、平均分数)
- */
- #include<stdio.h>
- #include<stdlib.h>
- struct student{
- char sno[20];
- char name[20];
- int score[3];
- };
- main()
- {
- int i;
- struct student * stu[2];
- //申请2块学生类数据
- for(i=0;i<2;i++)
- stu[i]=(struct student *)malloc(sizeof(struct student));
- //输入数据
- for(i=0;i<2;i++)
- {
- printf("--------请输入第%d个学生信息的学号、姓名、三科对应分数--------\n",i+1);
-
- printf("请输入第%d个学生的学号:",i+1) ;
- gets(stu[i]->sno);//输入学号
-
- printf("\n");
-
- printf("请输入第%d个学生的姓名:",i+1) ;
- gets(stu[i]->name);//输入姓名
-
- printf("\n");
-
- printf("请输入第%d个学生的三科对应成绩:",i+1) ;
- scanf("%d %d %d",&stu[i]->score[0],&stu[i]->score[1],&stu[i]->score[2]); //输入分别对应成绩
-
- getchar();
- printf("\n");
-
- }
- }
复制代码
|
-
|