From 773b6d77964ae2a27738acfc1842bc31ffcfec0c Mon Sep 17 00:00:00 2001 From: "1052720016@qq.com" <1052720016@qq.com> Date: Tue, 8 Jan 2019 16:15:27 +0800 Subject: [PATCH] second commit --- 1(1)(1).c | 75 --------------- 2.c | 221 +++++++++++++++++++++++++++++++++++++++++++ 1(1)(1).exe => 2.exe | Bin 105470 -> 105470 bytes 3 files changed, 221 insertions(+), 75 deletions(-) delete mode 100644 1(1)(1).c create mode 100644 2.c rename 1(1)(1).exe => 2.exe (99%) diff --git a/1(1)(1).c b/1(1)(1).c deleted file mode 100644 index bab7fd8..0000000 --- a/1(1)(1).c +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include -#include -#include -#include -struct birth -{ - int year,month,day; -}; -struct student -{ - int number,age,tel[20]; - char name[10],sex,address[20]; - char E_mail[20]; - struct birth birthday; - struct student *link; -}; -void show() -{ - printf("请输入数字加回车键进行选择:\n"); - printf("1.学生信息录入功能(学生信息用文件保存)-输入\n"); - printf("2.学生信息浏览功能-输出\n"); - printf("3.学生信息查询功能-按学号查询,按姓名查询\n"); - printf("4.学生信息的删除与修改\n"); - printf("按其他任意键加回车退出程序\n"); -} -void credit(int n) -{ - FILE *fp; - char fpname[20]; - struct student *head,*next,*end; - int i; - printf("请输入用于存放文件的路径及路径名:"); - scanf("%s",fpname); - getchar(); - fp=fopen(fpname,"w+"); - head=(struct student *)malloc(sizeof(struct student)); - printf("请输入学生学号 姓名 性别 出生年 月 日 地址 电话 e_mail:"); - scanf("%d %s %c %d %d %d %s %s %s",&head->number,&head->name,&head->sex,&(*head).birthday.year,&(*head).birthday.month,&(*head).birthday.day,head->address,head->tel,head->E_mail); - getchar(); - fprintf(fp,"%d %s %c %d %d %d %s %s %s",&head->number,&head->name,&head->sex,&(*head).birthday.year,&(*head).birthday.month,&(*head).birthday.day,head->address,head->tel,head->E_mail); - end=head; - for(i=0;inumber,&head->name,&head->sex,&(*head).birthday.year,&(*head).birthday.month,&(*head).birthday.day,head->address,head->tel,head->E_mail); - getchar(); - fprintf(fp,"%d %s %c %d %d %d %s %s %s",&head->number,&head->name,&head->sex,&(*head).birthday.year,&(*head).birthday.month,&(*head).birthday.day,head->address,head->tel,head->E_mail); - end->link=next; - end=next; - end->link=NULL; - } - fclose(fp); -} -void main () -{ - char get,get2; - int n; - while(1) - { - show(); - get=getchar(); - getchar(); - switch(get) - { - case '1': - printf("请输入学生人数:"); - scanf("%d",&n); - getchar(); - credit(n); - break; - } - } -} diff --git a/2.c b/2.c new file mode 100644 index 0000000..b3a20df --- /dev/null +++ b/2.c @@ -0,0 +1,221 @@ +#include +#include +#include +#include +#include +struct birth +{ + int year,month,day; +}; +struct student +{ + int number,age,tel[20]; + char name[10],sex,address[20]; + char E_mail[20]; + struct birth birthday; + struct student *link; +}; +void show() +{ + printf("请输入数字加回车键进行选择:\n"); + printf("1.学生信息录入功能(学生信息用文件保存)-输入\n"); + printf("2.学生信息浏览功能-输出\n"); + printf("3.学生信息查询功能-按学号查询,按姓名查询\n"); + printf("4.学生信息的删除与修改\n"); + printf("按其他任意键加回车退出程序\n"); +} +void credit(int n) +{ + FILE *fp; + char fpname[20]; + struct student *head,*next,*end; + int i; + printf("请输入用于存放文件的路径及路径名:"); + scanf("%s",fpname); + getchar(); + fp=fopen(fpname,"w+"); + head=(struct student *)malloc(sizeof(struct student)); + printf("请输入学生学号 姓名 性别 出生年 月 日 地址 电话 e_mail:"); + scanf("%d %s %c %d %d %d %s %s %s",&head->number,&head->name,&head->sex,&(*head).birthday.year,&(*head).birthday.month,&(*head).birthday.day,head->address,head->tel,head->E_mail); + getchar(); + fprintf(fp,"%d %s %c %d %d %d %s %s %s",&head->number,&head->name,&head->sex,&(*head).birthday.year,&(*head).birthday.month,&(*head).birthday.day,head->address,head->tel,head->E_mail); + end=head; + for(i=0;inumber,&head->name,&head->sex,&(*head).birthday.year,&(*head).birthday.month,&(*head).birthday.day,head->address,head->tel,head->E_mail); + getchar(); + fprintf(fp,"%d %s %c %d %d %d %s %s %s",&head->number,&head->name,&head->sex,&(*head).birthday.year,&(*head).birthday.month,&(*head).birthday.day,head->address,head->tel,head->E_mail); + end->link=next; + end=next; + end->link=NULL; + } + fclose(fp); +} +int show2(int n) +{ + + FILE *fp; + int i; + char fpname[20]; + struct student *head; + head=(struct student *)malloc(sizeof(struct student)); + printf("请输入用于存放信息的文件路径及文件名:"); + gets(fpname); + fp=fopen(fpname,"r+"); + for(i=0;inumber,&head->name,&head->sex,&(*head).birthday.year,&(*head).birthday.month,&(*head).birthday.day,head->address,head->tel,head->E_mail); + printf("%d %s %c %d %d %d %s %s %s",&head->number,&head->name,&head->sex,&(*head).birthday.year,&(*head).birthday.month,&(*head).birthday.day,head->address,head->tel,head->E_mail); + fclose(fp); + } +} +int search1(int n) +{ +int i,checkname; +FILE *fp; +char fpname[20]; +struct student *head; +head=(struct student *)malloc(sizeof(struct student)); +printf("请输入存放信息的文件路径及文件名:"); +gets(fpname); +fp=fopen(fpname,"r+"); +printf("请输入要查询信息的学生学号:"); +scanf("%d",&checkname); +getchar(); +for(i=0;inumber,&head->name,&head->sex,&(*head).birthday.year,&(*head).birthday.month,&(*head).birthday.day,head->address,head->tel,head->E_mail); + if(checkname==head->number) + { + printf("%d %s %c %d %d %d %s %s %s\n",&head->number,&head->name,&head->sex,&(*head).birthday.year,&(*head).birthday.month,&(*head).birthday.day,head->address,head->tel,head->E_mail); + fclose(fp); + return(1); + } +} + printf("未找到"); +} +int search2(int n) +{ + int i; + FILE *fp; + char fpname[20],checkname[20]; + struct student *head; + head=(struct student *)malloc(sizeof(struct student)); + printf("请输入存放信息的文件路径及文件名:"); + gets(fpname); + fp=fopen(fpname,"r+"); + printf("请输入要查询信息的学生姓名:"); + scanf("%s",&checkname); + for(i=0;inumber,&head->name,&head->sex,&(*head).birthday.year,&(*head).birthday.month,&(*head).birthday.day,head->address,head->tel,head->E_mail); + if(strcmp(checkname,head->name)==0) + { + for(i=0;inumber,&head->name,&head->sex,&(*head).birthday.year,&(*head).birthday.month,&(*head).birthday.day,head->address,head->tel,head->E_mail); + fclose(fp); + return(1); + } + } + printf("未找到\n"); +} +int most(n) +{ + FILE *fp; + char get; + char fpname[20]; + struct student *ans[500]; + int i; + char checkname[10]; + printf("请输入存放信息的文件路径及文件名:"); + gets(fpname); + fp=fopen(fpname,"r+"); + ans[0]=(struct student *)malloc(sizeof(struct student)); + fscanf(fp,"%d %s %c %d %d %d %s %s %s",&ans[0]->number,&ans[0]->name,&ans[0]->sex,&(*ans[0]).birthday.year,&(*ans[0]).birthday.month,&(*ans[0]).birthday.day,ans[0]->address,ans[0]->tel,ans[0]->E_mail); + for(i=0;inumber,&ans[i]->name,&ans[i]->sex,&(*ans[i]).birthday.year,&(*ans[i]).birthday.month,&(*ans[i]).birthday.day,ans[i]->address,ans[i]->tel,ans[i]->E_mail); + ans[i-1]->link=ans[i]; + } + ans[i]->link=NULL; + printf("如果想修改信息请输入1加回车键,想删除信息输入2加回车键:"); + get=getchar(); + getchar(); + if(get=='1') + { + printf("请输入要修改信息的学生姓名:"); + scanf("%s",checkname); + getchar(); + for(i=0;iname)==0) + { + printf("请输入学生新信息 学号 姓名 性别 出生年 月 日 地址 电话 e-mail:"); + scanf("%d %s %c %d %d %d %s %s %s",&ans[i]->number,&ans[i]->name,&ans[i]->sex,&(*ans[i]).birthday.year,&(*ans[i]).birthday.month,&(*ans[i]).birthday.day,ans[i]->address,ans[i]->tel,ans[i]->E_mail); + getchar(); + } + } + } + if(get=='2') + { + printf("请输入要删除的学生姓名:"); + scanf("%s",checkname); + getchar(); + for(i=0;iname)==0) + { + ans[i-1]->link=ans[i]->link; + n--; + break; + } + } + } + fp=fopen(fpname,"w+"); + for(i=0;inumber,&ans[i]->name,&ans[i]->sex,&(*ans[i]).birthday.year,&(*ans[i]).birthday.month,&(*ans[i]).birthday.day,ans[i]->address,ans[i]->tel,ans[i]->E_mail); + } + fclose(fp); + return(n); +} +void main () +{ + char get,get2; + int n; + while(1) + { + show(); + get=getchar(); + getchar(); + switch(get) + { + case '1': + printf("请输入学生人数:"); + scanf("%d",&n); + getchar(); + credit(n); + break; + case '2': + show2(n); + break; + case '3': + printf("按学号查找输入1加回车键,按姓名查找输入2加回车键:"); + get2=getchar(); + getchar(); + if(get2=='1') + search1(n); + if(get2=='2') + search2(n); + break; + case '4': + n=most(n); + break; + } + if(get!='1'&&get!='2'&&get!='3'&&get!='4') + break; + } +} diff --git a/1(1)(1).exe b/2.exe similarity index 99% rename from 1(1)(1).exe rename to 2.exe index 0f70fe7528af9809951eb04bd6a4fd29dc817e8a..06c1b6138013c717bd7a27b08b9592477120bbe9 100644 GIT binary patch delta 25 hcmeyjo$cRtwh0|f5rGrC{Fq<;XKcK^^){pOYyhL@3_Ab- delta 25 hcmeyjo$cRtwh0|fr$Q!n`7y^ZGd14cdYe&sHUON|3nu^o