可以给出上一个问题修改后的代码吗
时间: 2024-03-19 10:45:09 浏览: 17
当然可以,这里是修改后的代码:
```c
void change() {
printf("\n请输入学生的学号:");
int p,o,m;
scanf("%d",&o);
for(p=0;p<STUDENT_NUM;p++) {
if(o==student[p].no) {
printf("\n学号 姓名 年龄 性别 班级 宿舍 电话号码\n");
printf("%-4d%-4s%-4d%-3s%-4d%-5s%s\n",student[p].no,student[p].name,student[p].age,student[p].sex,student[p].class,student[p].address,student[p].phone);
break;
}
}
if(p==STUDENT_NUM) {
printf("该学号不存在\n");
return;
}
printf("\n是否修改\n1.是 2.否\n");
scanf("%d",&m);
if(m==1) {
while(1) {
printf("\n请输入姓名:\n");
getchar();
scanf("%s",student[p].name);
printf("请输入年龄:\n");
scanf("%d",&student[p].age);
printf("请输入性别:\n");
getchar();
scanf("%s",student[p].sex);
printf("请输入班级:\n");
scanf("%d",&student[p].class);
printf("请输入宿舍:\n");
getchar();
scanf("%s",student[p].address);
printf("请输入电话:\n");
scanf("%s",student[p].phone);
printf("\n学号 姓名 年龄 性别 班级 宿舍 电话号码\n");
printf("%-4d%-4s%-4d%-3s%-4d%-5s%s\n",student[p].no,student[p].name,student[p].age,student[p].sex,student[p].class,student[p].address,student[p].phone);
printf("\n1.重新修改 2.结束\n");
scanf("%d",&m);
if(m==2) {
printf("\n返回菜单\n");
break;
} else if(m!=1) {
printf("\n输入错误,请重新输入\n");
}
}
} else if(m==2) {
printf("\n返回菜单\n");
} else {
printf("\n输入错误,请重新输入\n");
}
}
```
修改后的代码解决了问题,并且也加上了一些输入的错误判断,使得程序更加健壮。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)