| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2208 人关注过本帖
标题:这个程序错在哪里,能编译但运行出错
取消只看楼主 加入收藏
ycchzq1996
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-6-15
结帖率:0
收藏
已结贴  问题点数:20 回复次数:0 
这个程序错在哪里,能编译但运行出错
#include<stdio.h>
 #include <string.h>
 #define N 6
    struct employee
    {
        int number,age,wage;
        char name[20],sex[10],address[30],xueli[20];
        long int telephone;
    }
    em[N];
    int a=N;
    int *p=&a;
    main()
    {
        void search();
        void search_name();
        void search_xueli();
        void search_number();
        void load();
        void display();
        void del();
        void input();
        void add();
        void save();
        int n;
        printf("\n");
        printf("        ******************职工信息管理****************\n");
        printf("\n");
        printf("                        1.录入职工信息\n");
        printf("                        2.浏览职工信息\n");
        printf("                        3.查询职工信息\n");
        printf("                        4.删除职工信息\n");
        printf("                        5.添加职工信息\n");
        printf("                        6.退出\n");
        printf("\n");
        scanf("%d",&n);
        switch(n)
        {
        case 1:printf("              ◆◆◆输入职工信息◆◆◆\n");
            printf("\n");
            input();
            main();
            break;
        case 2:printf("              ◆◆◆浏览职工信息◆◆◆\n");
            printf("\n");
            display(*p);
            main();
            break;
        case 3:printf("              ◆◆◆查询职工信息◆◆◆\n");
            printf("\n");
            search();
            break;
        case 4:printf("              ◆◆◆删除职工信息◆◆◆\n");
            printf("\n");
            del(p);
            break;
        case 5:printf("              ◆◆◆添加职工信息◆◆◆\n");
            printf("\n");
            add(p);
            break;
        case 6:exit(0);
            break;
        default :break;
        }
    }
    void input()
    {
        int i;
        for(i=0;i<N;i++)
        {
            printf("请输入职工号: ");
            scanf("%d",&em[i].number);
            printf("请输入姓名:  ");
            scanf("%s",em[i].name);
            printf("请输入性别:  ");
            scanf("%s",&em[i].sex);
            printf("请输入年龄:  ");
            scanf("%d",&em[i].age);
            printf("请输入学历:  ");
            scanf("%s",em[i].xueli);
            printf("请输入工资:  ");
            scanf("%d",&em[i].wage);
            printf("请输入住址:  ");
            scanf("%s",em[i].address);
            printf("请输入电话:  ");
            scanf("%d",&em[i].telephone);
            printf("\n");
        }
        printf("\n创建完毕!\n");
        save(N);
    }
    void save(int m)
    {
        int i;
        FILE*fp;
        if(!(fp=fopen("d://bbb.txt","w")))
        {
            printf("打开失败");
            exit(0);
        }
        for(i=0;i<m;i++)
            fprintf(fp,"M %8s %5s ] %8s ] %8s ?\n",em[i].number, em[i].name,em[i].sex,em[i].age,em[i].xueli,em[i].wage, em[i].address,em[i].telephone);
        fclose(fp); }
    void load(int b)
    {
        int i;
        FILE*fp;
        if(!(fp=fopen("d://bbb.txt","r")))
        {
            printf("打开失败");
            exit(0);
        }
        else  for(i=0;i<b;i++)
            fscanf(fp,"?%8s%5s]%8s]%8s?\n",&em[i].number,&em[i].name,&em[i].sex,&em[i].age,&em[i].xueli,&em[i].wage,&em[i].address,&em[i].telephone); fclose(fp);
    }
    void display(int a)
    {
        int i,b=a;
        load(b);
        printf("\n职工号\t    姓名\t性别\t年龄\t 学历\t     工资\t  住址\t  电话\n");
        for(i=0;i<a;i++)
        printf("%d\t%8s\t%s\t%d\t%8s    %d\t%s\t%d\n",em[i].number,em[i].name,em[i].sex,em[i].age,em[i].xueli,em[i].wage,em[i].address,em[i].telephone); printf("\n");
    }
    void search()
    {
        int t;
        printf("\n按职工号查询按1\n按姓名查询请按2");
        printf("\n按学历查询请按3\n返回主菜单请按4\n");
        scanf("%d",&t);
        switch(t)
        {
        case 1:  printf("\n按职工号查询\n");
            search_number();
            break; case 2:  printf("\n按姓名查询\n");
            search_name();
            break; case 3:
            printf("\n按学历查询\n");
            search_xueli();
            break;
        case 4:main();
            break;
        default :  printf("输入错误,请重新输入!\n");
            search();
            break;
   }
 }
    void search_number()
    {
        int i,number;  load(*p);
        printf("\n请输入要查询的职工号:");
        scanf("%d",&number);
        for(i=0;i<*p;i++)
            if(number==em[i].number)
            {
                printf("\n该职工信息如下:\n");
                printf("\n职工号\t    姓名\t性别\t年龄\t 学历\t     工资\t  住址\t  电话\n");
                printf("\n%d\t%8s\t%s\t%d\t%8s    %d\t%s\t%d\n",em[i].number,em[i].name,em[i].sex,em[i].age,em[i].xueli,em[i].wage,em[i].address,em[i].telephone);
                printf("\n"); break; } if(i==*p)  printf("\n查无此人\n");  search();
 }
    void search_name()
    {
        int i;
        char name[20];
        load(*p);
        printf("\n请输入要查询的姓名:");
        scanf("%s",name);
        for(i=0;i<*p;i++) if(!strcmp(em[i].name,name))
        {
            printf("\n该职工信息如下:\n");
            printf("\n职工号\t    姓名\t性别\t年龄\t 学历\t     工资\t  住址\t  电话\n");
            printf("\n%d\t%8s\t%s\t%d\t%8s    %d\t%s\t%d\n",em[i].number,em[i].name,em[i].sex,em[i].age,em[i].xueli,em[i].wage,em[i].address,em[i].telephone);
            printf("\n");
            break;
        }
        if(i==*p)
            printf("\n查无此人\n");
            search();
   }
    void search_xueli()
    {
        int i,k=0;
        char xueli[20];
        load(*p);
        printf("\n请输入要查询的学历:");
        scanf("%s",xueli);
        for(i=0;i<*p;i++)
            if(!strcmp(em[i].xueli,xueli))
            {
                printf("职工号\t    姓名\t性别\t年龄\t 学历\t     工资\t  住址\t  电话\n");
                printf("%d\t%8s\t%s\t%d\t%8s    %d\t%s\t%d\n",em[i].number,em[i].name,em[i].sex,em[i].age,em[i].xueli,em[i].wage,em[i].address,em[i].telephone);
    }
            for(i=0;i<*p;i++)
            {
                if(!strcmp(em[i].xueli,xueli)) break; else k++;
    }
            if(k==*p)
                printf("\n查无此人\n");
            search();
    }
            void del(int *b)
            {
                int i,t,j,m;
                int a=*b;
                char name[20];
                printf("\n所有职工信息:\n");
                display(a);
                printf("\n请输入要删除职工的名字:");
                scanf("%s",name);
                for(i=0;i<a;i++)
                {
                    if(!strcmp(em[i].name,name))
                    {
                        printf("\n确认删除请按1\n取消请按2\n");
                        scanf("%d",&t);
                        if(t==1)
                        {
                            for(j=i;j<a-1;j++)
                            {
                                em[j].age=em[j+1].age;
                                em[j].wage=em[j+1].wage;
                                em[j].number=em[j+1].number;
                                em[j].telephone=em[j+1].telephone;
                                strcpy(em[j].xueli,em[j+1].xueli);
                                strcpy(em[j].name,em[j+1].name);
                                strcpy(em[j].address,em[j+1].address);
                                strcpy(em[j].sex,em[j+1].sex);
                            }
                            a--;
                            save(j);
                            break;
                        }
                        if(t==2) break;
                    }
                }
                if(i==a)
                    printf("\n输入错误,无此人\n");
                *b=a;
                printf("\n继续删除请按1\n浏览信息请按2\n返回主菜单请按3\n");
                scanf("%d",&m);
                switch(m)
                {
                case 1:del(p);
                    break;
                case 2:display(*b);
                    main();
                    break;
                case 3:main();
                    break;
                default:break;
                }
            }
            void add(int *a)
            {
                int i,n,m; FILE*fp;
                if(!(fp=fopen("d://bbb.txt","a")))
                {  printf("打开失败");
                   exit(0);
                }  printf("\n请输入想添加的人数:\n");
                scanf("%d",&n);
                for(i=*a;i<n+(*a);i++)
                {  
                    printf("请输入职工号: ");
                    scanf("%d",&em[i].number);
                    printf("请输入姓名:  ");
                    scanf("%s",em[i].name);
                    printf("请输入性别:  ");
                    scanf("%s",&em[i].sex);
                    printf("请输入年龄:  ");
                    scanf("%d",&em[i].age);
                    printf("请输入学历:  ");
                    scanf("%s",em[i].xueli);
                    printf("请输入工资:  ");
                    scanf("%d",&em[i].wage);
                    printf("请输入住址:  ");
                    scanf("%s",em[i].address);
                    printf("请输入电话:  ");
                    scanf("%d",&em[i].telephone);
                    printf("\n");
            }
                printf("\n添加完毕\n");
                for(i=*a;i<n+(*a);i++)
                    fprintf(fp,"M %8s %5s ] %8s ] %8s ?\n",em[i].number, em[i].name,em[i].sex,em[i].age,em[i].xueli,em[i].wage, em[i].address,em[i].telephone);
                fclose(fp);
                *a=*a+n;
                printf("\n浏览新信息请按1\n返回主菜单请按2\n");
                scanf("%d",&m);
                switch(m)
                {
                case 1:display(*a);
                    main();break;
                case 2:main();
                    break;
                default:break;
            }
            }
搜索更多相关主题的帖子: telephone employee display include search 
2015-06-15 22:26
快速回复:这个程序错在哪里,能编译但运行出错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018823 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved