请问我想在单个查询学生信息的时候修改成可根据学号和姓名两张搜索方式,应该怎么改呢
#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("语文成绩:\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;
printf("输入要查询信息的学生学号:\n");
char num[10];
int flag=1;
scanf("%s",&num);
for(VS=head;VS!=NULL;){
if(strcmp(VS->number,num)==0){
printf("成功找到!\n");
printf("学号:%s\t姓名:%s\n",VS->number,VS->name,VS->sex);
printf("语文:%d",VS->Chinese,VS->Math,VS->English);
flag=0;
break;
}
VS=VS->next;
}
if(flag){
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,VA->sex);
printf("语文:%d\tn",VA->Chinese,VA->Math,VA->English);
VA=VA->next;
}
}else{
printf("该系统中还未录入信息");
}
system("pause");
}
void Repair(){
system("cls");
struct Student *RS;
char num[10];
int flag = 1;
printf("输入要修改成绩学生的学号:\n");
scanf("%s",num);
for(RS=head;RS!=NULL;){
if(strcmp(RS->number,num)==0){
printf("成功找到该学生");
printf("学号:%s\t姓名:%s\n",RS->number,RS->name,RS->sex);
printf("语文:%d\n",RS->Chinese,RS->Math,RS->English);
flag = 0;
printf("学号:\n");
scanf("%s",&RS->number);
printf("姓名:\n");
scanf("%s",&RS->name);
printf("英语成绩:\n");
scanf("%d",&RS->English);
printf("修改成功");
system("pause");
}
RS=RS->next;
}
if(flag){
printf("输入信息有误,未查询到");
system("pause");
}
}
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();
}