#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();
struct teach* creatList();
void brow(struct teach *head);
void find(struct teach *head);
void findNo(struct teach *head,char no[]);
struct teach *del(struct teach *head,char gh[]);
int main(){
int dl=load();
int choice;
char gh[20];
struct teach *head,*p;
if(dl==1){
head=creatList();
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);
p=del(head,gh);
if(p!=NULL){
printf("序号 工号\t姓名\t工龄\t职称\t\t工资\t\t联系方式\n");
printf("%d %s\t%s\t%d\t%s\t\t%-.2f\t\t-s\n",p->xh,p->xm,p->gl,p->zc,p->gz,p->dh);
}
else
printf("删除失败\n");
break;
case 4:
break;
case 5:
break;
default:
return 0;
}
system("pause");
system("cls");
}
}
return 0;
}
struct teach *del(struct teach *head,char gh[]){
struct teach *pre,*p;
pre=head;
p=head->next;
while(head!=NULL){
if(strcmp(head->gh,gh)==0){
pre->next=p->next;
return p;
}
else{
pre=p;
p=p->next;
}
}
if(head==NULL)
return NULL;
}
void findNo(struct teach *head,char no[]){
head=head->next;
printf("序号 工号\t姓名\t工龄\t职称\t\t工资\t\t联系方式\n");
while(head!=NULL){
if(strcmp(head->gh,no)==0){
printf("%d %s\t%s\t%d\t%s\t\t%-.2f\t\t-s\n",head->xh,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){
printf("序号 工号\t姓名\t工龄\t职称\t\t工资\t\t联系方式\n");
head=head->next;
while(head){
printf("%d %s\t%s\t%d\t%s\t\t%-.2f\t\t-s\n",head->xh,head->xm,head->gl,head->zc,head->gz,head->dh);
head=head->next;
}
}
struct teach* creatList(){
FILE *fp;
fp=fopen("tea.txt","r");
if(fp==NULL){
}
struct teach t,*head,*temp,*tail;
head=(struct teach*)malloc(sizeof(struct teach));
head->next=NULL;
tail=head;
fscanf(fp,"%d %s %s %d %s %lf %s",&t.xh,t.gh,t.xm,&t.gl,t.zc,&t.gz,t.dh);
while(!feof(fp)){
temp=(struct teach*)malloc(sizeof(struct teach));
temp->xh=t.xh;
strcpy(temp->gh,t.gh);
strcpy(temp->xm,t.xm);
temp->gl=t.gl;
strcpy(temp->zc,t.zc);
temp->gz=t.gz;
strcpy(temp->dh,t.dh);
temp->next=NULL;
tail->next=temp;
tail=temp;
fscanf(fp,"%d %s %s %d %lf %lf %s",&t.xh,t.gh,t.xm,&t.gl,t.zc,&t.gz,t.dh);
}
return head;
}
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;
}
}
输完用户名和密码就不能往下进行,怎么回事呢?