| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1543 人关注过本帖
标题:删除不掉 修改也不行 求大佬改一下
只看楼主 加入收藏
骚的一批
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2018-3-16
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
删除不掉 修改也不行 求大佬改一下
#include <stdio.h>
#include <stdlib.h>
#include <wtypes.h>
#include <winbase.h>
#include <time.h>
#include <conio.h>
struct
{
    int choice;
    char name[50];
    char num[50];
    char wanges[50];
    char gread[50];
    char sex[20];
    char birth[50];
    char add[500];
    char pnum[50];
}
one;
FILE*fp;

void output();
void search();
void append();
void modify();
void delete();
void exit();
void nameway();
void numway();


void main()
{
    int m;
    while(1)
    {
        system("color f");
        printf("\n\n\n                   ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*\n\n");
        printf("                             欢迎使用职工信息管理系统\n\n");
        printf("                   ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*\n\n");
        printf("                  |     *     |  1.添加职工信息  |     *     |     \n");
        printf("                  |     *     |  2.查找职工信息  |     *     |     \n");
        printf("                  |     *     |  3.修改职工信息  |     *     |     \n");
        printf("                  |     *     |  4.删除职工信息  |     *     |     \n");
        printf("                  |     *     |  5.输出职工信息  |     *     |     \n");
        printf("                   ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*\n\n");
        printf("                               请输入对应的字符[ ]\b\b");
        scanf("%d",&m);
        if(m>=1&&m<=6)
        {
            switch(m)
            {
                case 1: append();
                break;
                case 2: search();
                break;
                case 3: modify();
                break;
                case 4: delete();
                break;
                case 5: output();
                break;
            }
        }
        else
        {
            printf("\n\n无效指令,请重试");
        }
    }
}

void append()
{
    int choice;
    system("cls");
    if((fp=fopen("worker.xls","a"))==NULL)
    {
        printf("\n对不起,无法打开信息文件。\n\n");
        exit(0);
    }
    printf("                    *********************************\n");
    printf("                         请输入需要添加的职工信息      \n");
    printf("                    *********************************\n");
    printf("         姓名,职工号,性别,工资,出生年月,学历,住址,电话\n");
    scanf("%s%s%s%s%s%s%s%s",one.name,one.num,one.sex,one.wanges,one.birth,one.gread,one.add,one.pnum);
    fprintf(fp,"%-20s%-20s%-20s%-20s%-20s%-20s%-20s%-20s\n",one.name,one.num,one.sex,one.wanges,one.birth,one.gread,one.add,one.pnum);
    fclose(fp);
    printf("\n\n操作完成,请按下回车继续");
    choice=getch();
    system("cls");
}

void output()
{
    int choice;
    system("cls");
    if((fp=fopen("worker.xls","r"))==NULL)
    {
        system("cls");
        printf("\n对不起,无法查询信息文件。\n\n");
        exit(0);
    }
    printf("                          =========================\n");
    printf("                                  职工信息\n");
    printf("                          =========================\n");
    printf("          姓名,职工号,性别,工资,出生年月,学历,住址,电话\n\n");
    while(!feof(fp))
    {
        fscanf(fp,"%s%s%s%s%s%s%s%s\n",one.name,one.num,one.sex,one.wanges,one.birth,one.gread,one.add,one.pnum);
        printf("%-20s%-20s%-20s%-20s%-20s%-20s%-20s%-20s\n",one.name,one.num,one.sex,one.wanges,one.birth,one.gread,one.add,one.pnum);
    }
    fclose(fp);
    printf("\n\n显示完毕,请按下回车继续");
    choice=getch();
    system("cls");
}



void search()
{
    int choice;
    int k=0;
    char wan[50];
    printf("\n请输入要查询的工资:");
    scanf("%s",wan);
    if((fp=fopen("worker.xls","rb"))==NULL)
    {
        printf("\n对不起,无法查询信息文件。");
        exit(0);
    }
    while(!feof(fp))
    {
        fscanf(fp,"%s%s%s%s%s%s%s%s\n",one.name,one.num,one.sex,one.wanges,one.birth,one.gread,one.add,one.pnum);
        if(strcmp(wan,one.wanges)==0)
        {
            printf("\n\n已查到,记录为:");
            printf("%-20s%-20s%-20s%-20s%-20s%-20s%-20s%-20s\n",one.name,one.num,one.sex,one.wanges,one.birth,one.gread,one.add,one.pnum);
            k=1;
        }
    }
    if(k==0)
    {
        printf("\n\n对不起,查无此人。\n");
        fclose(fp);
    }
    printf("\n\n操作完成,请按下回车继续");
    choice=getch();
    system("cls");
}



void modify()
{
    int choice;
    int k=0;
    long a;
    char name[50];
    system("cls");
    printf("\n请输入您要修改的职工姓名:");
    scanf("%s",name);
    if((fp=fopen("worker.xls","r+"))==NULL)
    {
        printf("\n对不起,无法查询信息文件。");
        exit(0);
    }
    while(!feof(fp))
    {
        a=ftell(fp);
        fscanf(fp,"%s%s%s%s%s%s%s%s\n",one.name,one.num,one.sex,one.wanges,one.birth,one.gread,one.add,one.pnum);
        if(!strcmp(name,one.name))
        {
            k=1;
            break;
        }
    }
    if(k)
    {
        printf("\n已查到,记录为:");
        printf("\n%-20s%-20s%-20s%-20s%-20s%-20s%-20s%-20s\n",one.name,one.num,one.sex,one.wanges,one.birth,one.gread,one.add,one.pnum);
        printf("\n请输入需要修改的信息。\n");
        printf("(请按照:姓名,职工号,性别,工资,出生年月,学历,住址,电话顺序输入)\n");
        scanf("%s%s%s%s%s%s%s%s%s",one.name,one.num,one.sex,one.wanges,one.birth,one.gread,one.add,one.pnum);
        fseek(fp,a,0);
        fprintf(fp,"%-20s%-20s%-20s%-20s%-20s%-20s%-20s%-20s\n",one.name,one.num,one.sex,one.wanges,one.birth,one.gread,one.add,one.pnum);
    }
    else
    {
        printf("\n对不起,查无此人,无法修改。");
        fclose(fp);
    }
    printf("\n\n操作完成,请按下回车继续");
    choice=getch();
    system("cls");
}

void delete()
{
    int m;
    int choice;
    int k=0;
    long a;
    char name[50];
    char valid[50];
    system("cls");
    printf("\n请输入您要修改的职工姓名:");
    scanf("%s",name);
    if((fp=fopen("worker.xls","r+"))==NULL)
    {
        printf("\n对不起,无法查询信息文件。");
        exit(0);
    }
    while(!feof(fp))
    {
        a=ftell(fp);
        fscanf(fp,"%s%s%s%s\n",one.name,one.num,one.sex,one.wanges,one.birth,one.gread,one.add,one.pnum);
        if(strcmp(name,one.name)==0)
        {
            k=1;
            break;
        }
    }
    if(k==1)
    {
        printf("\n已查到,记录为:");
        printf("\n%-20s%-20s%-20s%-20s%-20s%-20s%-20s%-20s\n",one.name,one.num,one.sex,one.wanges,one.birth,one.gread,one.add,one.pnum);
        printf("\n确定删除按1,不删除按0:");
        scanf("%d",&m);
        if(m==1)
        {
            fseek(fp,a,0);
            fprintf(fp,"%-20s%-20s%-20s%-20s%-20s%-20s%-20s%-20s\n","","","","");
        }
    }
    else
    {
        printf("\n对不起,查无此人。");
    }
    fclose(fp);
    printf("\n\n操作完成,请按下回车继续");
    choice=getch();
    system("cls");
}
搜索更多相关主题的帖子: name num one void printf 
2018-03-16 10:57
骚的一批
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2018-3-16
收藏
得分:0 
没人吗·
2018-03-16 11:50
loboce
Rank: 2
等 级:论坛游民
威 望:1
帖 子:26
专家分:96
注 册:2014-6-7
收藏
得分:20 
这个程序处理输入输出的地方还需要细腻一点,比如,如果输入了1到5之外的字符,你的程序就挂了。停在那里,等待你的输入,输入缓冲区还没刷新。三言两语跟你说不完
2018-03-16 12:45
loboce
Rank: 2
等 级:论坛游民
威 望:1
帖 子:26
专家分:96
注 册:2014-6-7
收藏
得分:0 
如果不能读入正确的字符,就无法通过break语句跳出那个while(1)无限循环,你的程序就挂在那里。你可以更深入地了解一下scanf(),这对你来说更加好一点。你可以自己去改,改不了我可以再帮你
2018-03-16 12:56
骚的一批
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2018-3-16
收藏
得分:0 
回复 4楼 loboce
谢谢
2018-03-16 17:50
快速回复:删除不掉 修改也不行 求大佬改一下
数据加载中...
 
   



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

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