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 0f70fe7..06c1b61 100644 Binary files a/1(1)(1).exe and b/2.exe differ