From 12d594ef54ffb96d21312d495fa50bbff9b430d2 Mon Sep 17 00:00:00 2001 From: m7wzyfpis <1040766652@qq.com> Date: Mon, 13 Nov 2023 17:03:29 +0800 Subject: [PATCH] search --- searching.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 searching.c diff --git a/searching.c b/searching.c new file mode 100644 index 0000000..c916bbb --- /dev/null +++ b/searching.c @@ -0,0 +1,92 @@ +#include + +extern int n; + +void Seek(void) +{ + int b,flag=0;//flag为标志变量,用于判断输入学号后是否能正常操作 + char a[LEN]; + + if(n!=0) + { + printf("\n1.按学号查找:\n"); + printf("2.按学院查找:\n"); + printf("3.按专业查找:\n"); + printf("4.按班级查找:\n"); + printf("请从序号1-4中选择:"); + scanf("%d",&b); + if(b>=1 && b<=4) + { + printf("请输入要查找的名称:"); + scanf("%s",&a); + p=head;//指针指向开头 + switch(b) + { + case 1://按学号查找 + do + { + if(strcmp(a,p->StudentId)==0) + { + printf("\n信息已被找到:\n学号\t\t姓名\t\t年龄\t性别\t学院\t\t专业\t\t班级\t\t电话\n"); + printf("%-16s%-16s%-8s%-8s%-16s%-16s%-16s%-16s\n",p->StudentId,p->StudentName,p->StudentAge,p->StudentSex,p->StudentCollege,p->StudentMajor,p->StudentClass,p->StudentTelephoneNumber); + flag=1; + } + p=p->next;//指针指向下一个节点 + }while(p!=NULL); + break; + case 2://按学院查找 + do + { + if(strcmp(a,p->StudentCollege)==0) + { + printf("\n学号\t\t姓名\t\t年龄\t性别\t学院\t\t专业\t\t班级\t\t电话\n"); + printf("%-16s%-16s%-8s%-8s%-16s%-16s%-16s%-16s\n",p->StudentId,p->StudentName,p->StudentAge,p->StudentSex,p->StudentCollege,p->StudentMajor,p->StudentClass,p->StudentTelephoneNumber); + flag=1; + } + p=p->next; + }while(p!=NULL); + break; + case 3://按专业查找 + do + { + if(strcmp(a,p->StudentMajor)==0) + { + printf("\n学号\t\t姓名\t\t年龄\t性别\t学院\t\t专业\t\t班级\t\t电话\n"); + printf("%-16s%-16s%-8s%-8s%-16s%-16s%-16s%-16s\n",p->StudentId,p->StudentName,p->StudentAge,p->StudentSex,p->StudentCollege,p->StudentMajor,p->StudentClass,p->StudentTelephoneNumber); + flag=1; + } + p=p->next; + }while(p!=NULL); + break; + case 4://按班级查找 + do + { + if(strcmp(a,p->StudentClass)==0) + { + printf("\n学号\t\t姓名\t\t年龄\t性别\t学院\t\t专业\t\t班级\t\t电话\n"); + printf("%-16s%-16s%-8s%-8s%-16s%-16s%-16s%-16s\n",p->StudentId,p->StudentName,p->StudentAge,p->StudentSex,p->StudentCollege,p->StudentMajor,p->StudentClass,p->StudentTelephoneNumber); + flag=1; + } + p=p->next; + }while(p!=NULL); + break; + } + system("pause"); + if(flag==0)//a的值输入错误 + { + printf("\nwrong input\n"); + system("pause"); + } + } + else//b的值输入错误 + { + printf("wrong input\n"); + system("pause"); + } + } + else//未添加数据 + { + printf("\nwrong input\n"); + system("pause"); + } +} \ No newline at end of file