2条回答 默认 最新
- CSDN专家-赖老师(软件之家) 2021-06-18 09:25关注
#include<stdio.h> #include <string.h> #include <stdlib.h> struct teach{ int xh; char gh[20]; char xm[20]; int gl; char zc[20]; double gz; char dh[13]; struct teach *next; }; void menu1(); void menu2(); void menuM(); int load(); void creatList(struct teach *head); void brow(struct teach *head); void find(struct teach *head); void findNo(struct teach *head,char no[]); void del(struct teach *head,char gh[]); int main(){ int choice; char gh[20]; struct teach *head; int dl=load(); if(dl==1){ creatList(head); while(1){ menuM(); printf("请选择操作(0-5):\n"); scanf("%d",&choice); switch(choice){ case 1: brow(head); break; case 2: find(head); break; case 3: printf("请输入工号:\n"); scanf("%s",gh); del(head,gh); break; case 4: break; case 5: break; default: return 0; } system("pause"); system("cls"); } } return 0; } void del(struct teach *head,char gh[]){ struct teach *pre,*p; if(head==NULL){ printf("表为空!\n"); return; } pre=head; p=head->next; while(p!=NULL){ if(strcmp(p->gh,gh)==0){ pre->next=p->next; printf("删除成功!\n"); printf("序号 工号\t姓名\t工龄\t职称\t工资\t联系方式\n"); printf("%d %s\t%s\t%d\t%s\t\t%-6.2f\t\t%-s\n", p->xh,p->gh,p->xm,p->gl,p->zc,p->gz,p->dh); free(p); break; } pre=p; p=p->next; } if(p == NULL) printf("查无此人!\n"); } void findNo(struct teach *head,char no[]){ if(head==NULL){ printf("表为空!\n"); return; } head=head->next; printf("序号 工号\t姓名\t工龄\t职称\t工资\t联系方式\n"); while(head){ if(strcmp(head->gh,no)==0){ printf("%d %s\t%s\t%d\t%s\t\t%-6.2f\t\t%-s\n", head->xh,head->gh,head->xm,head->gl,head->zc,head->gz,head->dh); break; } head=head->next; } if(head == NULL) printf("查无此人!\n"); } void find(struct teach *head){ int c,tage; char no[20]; while(1){ printf("**********************************************\n"); printf("* 1-----------按教工工号信息查询 *\n"); printf("* 2-----------按教工工龄信息查询 *\n"); printf("* 0-----------退出 *\n"); printf("**********************************************\n"); printf("请选择(0-2):\n"); scanf("%d",&c); if(c==1){ printf("gh:"); scanf("%s",no); findNo(head,no); } else if(c==2){ printf("gl:"); scanf("%d",&tage); //findTage(head,tage); } else return ; } } void menuM(){ printf("**********************************************\n"); printf("* 1-----------教工信息浏览 *\n"); printf("* 2-----------教工信息查询 *\n"); printf("* 3-----------教工信息删除 *\n"); printf("* 4-----------教工信息插入 *\n"); printf("* 5-----------教工信息修改 *\n"); printf("* 0-----------退出 *\n"); printf("**********************************************\n"); } void brow(struct teach *head){ if(head==NULL){ printf("表为空!\n"); return; } printf("序号 工号\t姓名\t工龄\t职称\t工资\t联系方式\n"); head=head->next; while(head){ printf("%d %s\t%s\t%d\t%s\t\t%-6.2f\t\t%-s\n", head->xh,head->gh,head->xm,head->gl,head->zc,head->gz,head->dh); head=head->next; } } void creatList(struct teach *head){ FILE *fp; struct teach *tmp,*tail; fp=fopen("tea.txt","at+"); if(fp==NULL){ printf("Open file fail!\n"); head=NULL; return; } head =(struct teach*)malloc(sizeof(struct teach)); head->next=NULL; tail= head; while(1){ tmp=(struct teach*)malloc(sizeof(struct teach)); tmp->next=NULL; if(fscanf(fp,"%d %s %s %d %s %lf %s",&tmp->xh,tmp->gh,tmp->xm,&tmp->gl,tmp->zc,&tmp->gz,tmp->dh)!=7) break; if(head->next==NULL){ head->next = tmp; tail = tmp; }else{ tail->next=tmp; tail = tmp; } } fclose(fp); free(tmp); } void menu1(){ printf("*************************************\n"); printf("*********1------------登陆***********\n"); printf("*********0------------退出***********\n"); printf("*************************************\n"); } int load(){ int c=3,dl; char name[20],pass[10]; while(c){ system("cls"); menu1(); printf("请选择(0/1):\n"); scanf("%d",&dl); getchar(); if(dl==1){ printf("请输入用户名:\n"); scanf("%s",name); printf("请输入密码:\n"); scanf("%s",pass); c--; if(strcmp("aaa",name)==0&&strcmp("123456",pass)==0){//登陆成功创建链表 return 1; }else if(c!=0){ printf("用户名或密码错误,还有%d次机会\n",c); system("pause"); } else return 0; } else return 0; } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?