删除不掉 修改也不行 求大佬改一下
#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");
}