为什么不能进行下一步呢?

#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;
    }
}

输完用户名和密码就不能往下进行,怎么回事呢?

tea.txt文件最好先建立起来,因为代码里除了文件读入数据,没有增加数据的地方,修改完善如下,供参考。:

#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  dl=load();
    int  choice;
    char gh[20];
    struct teach *head,*p;
    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[]){
    if(head==NULL){
        printf("表为空!\n");
        return;
    }
    struct teach *pre,*p;
    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;
    fp=fopen("tea.txt","r");
    if(fp==NULL){
       printf("Open file fail!\n");
       head=NULL;
       return;
    }
    struct teach *tmp,*tail;
    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;
    }
}

 

是哪一步不能正常往下走呢?把问题描述详细一点,方便锁定问题。

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632