能不能帮我看一下哪里错了,我修改学生信息,修改的那个c语言成绩本来是修改成了56,但是再查询显示成绩是1579,一个毫无关系的数,但是修改的姓名和学号都是显示的正确的
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#define LEN sizeof(struct Student)
struct Student{
char number[20]; //学号
char name[10]; //姓名
int Chinese; //语文成绩
struct Student* next; //指向下一个数据的指针
};
struct Student* head = NULL;
struct Student* end = NULL;
void Menu(){
void Menu();
void Add();
void View();
void Delete();
void Repair();
void ViewAll();
system("cls");
printf("1、学生信息录入\n");
printf("2、学生单个成绩查询\n");
printf("3、查询全部学生成绩\n");
printf("4、修改学生信息\n");
printf("5、删除学生信息\n");
printf("6、退出系统\n");
int choice;
printf("请选择要使用的功能:\n");
loop:
scanf("%d",&choice);
switch (choice) {
case 1:
Add();
Menu();
case 2:
View();
Menu();
case 3:
ViewAll();
Menu();
case 4:
Repair();
Menu();
case 5:
Delete();
Menu();
case 6:
exit(0);
default:
printf("输入有误,请重新选择:");
goto loop;
}
}
void Add(){
system("cls");
int count;
printf("请输入要录入信息的个数:");
scanf("%d",&count);
struct Student *s1,*s2,*temp;
s1=s2=(struct Student*)malloc(LEN);
if(head==NULL){
head = s1;
}else{
end->next = s1 ;
}
int i = 1;
while(count>0){
printf("请输入第%d位学生信息:\n",i++);
printf("学号:\n");
scanf("%s",&s1->number);
printf("姓名:\n");
scanf("%s",&s1->name);
printf("c语言成绩:\n");
scanf("%d",&s1->Chinese);
count--;
s2->next=s1;
s2=s1;
s1=(struct Student*)malloc(LEN);
printf("添加成功!\n");
system("pause");
system("cls");
}
s2->next= NULL;
end = s2;
printf("全部添加成功!\n");
system("pause");
}
void View(){
system("cls");
struct Student *VS;
int choice;
printf("请输入查询方式:\n");
printf("1、按学号查询\n");
printf("2、按姓名查询\n");
loop:
scanf("%d",&choice);
if (choice != 1 && choice != 2) {
printf("输入有误,请重新选择:");
goto loop;
}
char str[20];
if (choice == 1) {
printf("请输入要查询信息的学生学号:\n");
scanf("%s", str);
for(VS=head;VS!=NULL;VS=VS->next){
if(strcmp(VS->number,str)==0){
printf("成功找到!\n");
printf("学号:%s\t姓名:%s\n",VS->number,VS->name);
printf("c语言:%d\n",VS->Chinese);
system("pause");
return;
}
}
} else if (choice == 2) {
printf("请输入要查询信息的学生姓名:\n");
scanf("%s", str);
for(VS=head;VS!=NULL;VS=VS->next){
if(strcmp(VS->name,str)==0){
printf("成功找到!\n");
printf("学号:%s\t姓名:%s\n",VS->number,VS->name);
printf("c语言:%d\n",VS->Chinese);
system("pause");
return;
}
}
}
printf("不好意思,未找到!\n");
system("pause");
}
void ViewAll(){
system("cls");
struct Student *VA;
if(head!=NULL){
printf("所有学生成绩如下:\n");
for(VA=head;VA!=NULL;){
printf("学号:%s\t姓名:%s\n",VA->number,VA->name);
printf("c语言:%d\tn",VA->Chinese);
VA=VA->next;
}
}else{
printf("该系统中还未录入信息");
}
system("pause");
}
void Repair(){
system("cls");
struct Student *RS;
int choice;
printf("请输入查询方式:\n");
printf("1.按照查询学号方式修改\n");
printf("2.按照查询姓名方式修改\n");
loop:
scanf("%d",&choice);
if (choice !=1&&choice !=2) {
printf("输入有误,请重新输入");
goto loop;
}
char str[20];
if (choice == 1) {
printf("请输入学号:\n");
scanf("%s",&str);
for(RS=head;RS!=NULL;RS=RS->next){
if(strcmp(RS->number,str)==0){
printf("成功找到该学生");
printf("学号:%s\t姓名:%s\n",RS->number,RS->name);
printf("c语言:%d\n",RS->Chinese);
printf("学号:\n");
scanf("%s",&RS->number);
printf("姓名:\n");
scanf("%s",&RS->name);
printf("c语言成绩:\n");
scanf("%s",&RS->Chinese);
printf("修改成功");
system("pause");
return;
}
}
}
else if (choice ==2) {
printf("请输入姓名:\n");
scanf("%s",&str);
for(RS=head;RS!=NULL;RS=RS->next) {
if(strcmp(RS->name,str)==0) {
printf("成功找到该学生");
printf("学号:%s\t姓名:%s\n",RS->number,RS->name);
printf("c语言:%d\n",RS->Chinese);
printf("学号:\n");
scanf("%s",&RS->number);
printf("姓名:\n");
scanf("%s",&RS->name);
printf("c语言成绩:\n");
scanf("%s",&RS->Chinese);
printf("修改成功");
system("pause");
return;
}
}
}
else {
printf("输入信息有误,未查询到 \n");
system("pause");
return 0;
}
}
void Delete(){
system("cls");
int flag =1;
while(flag){
printf("请输入要删除的学生学号:");
char num[10];
scanf("%s",&num);
struct Student * DS,*temp;
for(DS=head;DS!=NULL;){
if(strcmp(DS->number,num)==0){
if(DS==head){
head = DS->next;
flag = 0;
printf("删除成功!\n");
system("pause");
}else{
flag = 0;
printf("删除成功!\n");
temp->next= DS->next;
free(DS);
system("pause");
}
}
temp = DS;
DS=DS->next;
}
if(flag){
printf("未找到该学生学号!\n");
system("pause");
}
}
}
int main(){
void Menu();
void Add();
void View();
void Delete();
void Repair();
void ViewAll();
Menu();
}