各位,跪谢了!不能见死不救啊!
这个职工管理系统还要求能显示某年月以前和某年月以后出生的信息!该怎么办!大家帮帮我了!
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
struct person
{
char name[15];
char id[15];
char sex[15];
char birth[15];
char prof[15];
char educat[15];
char salary[15];
char marriage[15];
};
char filename[50];
FILE *fp;
void creat();
void output();
void search();
void lookfor();
void locate();
void append();
void modify();
void delete();
void main(void)
{
int m;
creat();
while(1)
{ printf("\n\n********************************************************************************");
printf("\ncreat the information of new employee,please enter 1");
printf("\nsearch the information of certain employee,please enter 2");
printf("\nmodify certain information of certain employee,please enter 3");
printf("\ndelete the information of certain employee,please enter 4");
printf("\noutput the information of all employees,please enter 5");
printf("\noutput tne man of certain prof,please enter 6");
printf("\noutput the man after certain date,please enter 7");
printf("\noutput the man before certain date,pleae enter 8");
printf("\noutput the man hasn't marry,please enter 9");
printf("\nexit,please enter 0\n\n");
printf("********************************************************************************\n");
scanf("%d",&m);
if(m>=0&&m<=9)
{
switch(m)
{
case 1: append(); break;
case 2: search(); break;
case 3: modify(); break;
case 4: delete(); break;
case 5: output(); break;
case 6: lookfor(); break;
case 7: search(); break;
case 8: search(); break;
case 9: locate(); break;
case 0: exit(0);
}
printf("\n\nfinish,choose agian:");
}
else
printf("\n\nerror,choose again:");
}
}
void creat()
{
struct person one;
printf("\n\n********************************************************************************");
printf("\n\n weilcome to employee information managemnet system\n");
printf("\n********************************************************************************\n");
printf("\nenter file name:");
scanf("%s",filename);
if((fp=fopen(filename,"w"))==NULL)
{
printf("\nfail!");
exit(1);
}
fprintf(fp,"%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s\n","name","id","sex","birth","prof","educat","salary","marriage");
printf("\nenter the name,id, sex,birth,prof,educat,salary and marriage(end with0)\n");
scanf("%s",one.name);
while(strcmp(one.name,"0"))
{
scanf("%s%s%s%s%s%s%s",one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
fprintf(fp,"%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s\n",one.name,one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
scanf("%s",one.name);
}
fclose(fp);
}
void output()
{
struct person one;
if((fp=fopen(filename,"r"))==NULL)
{
printf("\nfail!");
exit(1);
}
printf("\n\n%50s\n"," employee information management system\n\n");
while(!feof(fp))
{
fscanf(fp,"%s%s%s%s%s%s%s%s\n",one.name,one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
printf("%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s\n",one.name,one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
}
fclose(fp);
}
void append()
{
struct person one;
if((fp=fopen(filename,"a"))==NULL)
{
printf("\nfail!");
exit(1);
}
printf("\nenter new created employee's name,id, sex,birth,prof,educat,salary and marriage\n");
scanf("%s%s%s%s%s%s%s%s",one.name,one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
fprintf(fp,"%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s\n",one.name,one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
fclose(fp);
}
void search()
{
int k=0;
char namekey[8];
struct person one;
printf("\nenter name:");
scanf("%s",namekey);
if((fp=fopen(filename,"rb"))==NULL)
{
printf("\nfail!");
exit(1);
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s%s%s%s%s%s\n",one.name,one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
if(!strcmp(namekey,one.name))
{
printf("\n\nfind,here is:");
printf("\n%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s\n",one.name,one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
k=1;
}
}
if(!k)
printf("\n\nsorry,no such one!");
fclose(fp);
}
void lookfor()
{
int k=0;
char profkey[8];
struct person one;
printf("\nenter prof:");
scanf("%s",profkey);
if((fp=fopen(filename,"rb"))==NULL)
{
printf("\nfail!");
exit(1);
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s%s%s%s%s%s\n",one.name,one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
if(!strcmp(profkey,one.prof))
{
printf("\n\nfind,here is:");
printf("\n%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s\n",one.name,one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
k=1;
}
}
if(!k)
printf("\n\nsorry,no such one!");
fclose(fp);
}
void locate()
{
int k=0;
char marriagekey[8];
struct person one;
printf("\nenter marriage:");
scanf("%s",marriagekey);
if((fp=fopen(filename,"rb"))==NULL)
{
printf("\nfail!");
exit(1);
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s%s%s%s%s%s\n",one.name,one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
if(!strcmp(marriagekey,one.marriage))
{
printf("\n\nfind,here is:");
printf("\n%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s\n",one.name,one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
k=1;
}
}
if(!k)
printf("\n\nsorry,no such one!");
fclose(fp);
}
void modify()
{
int k=0;
long offset;
char namekey[8];
struct person one;
printf("\nenter name:");
scanf("%s",namekey);
if((fp=fopen(filename,"r+"))==NULL)
{
printf("\nfail!");
exit(1);
}
while(!feof(fp))
{
offset=ftell(fp);
fscanf(fp,"%s%s%s%s%s%s%s%s\n",one.name,one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
if(!strcmp(namekey,one.name))
{
k=1;
break;
}
}
if(k)
{
printf("\nfind,here is:");
printf("\n%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s",one.name,one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
printf("\nenter new name,id,sex,birth,prof,educat,salary and marriage:\n");
scanf("%s%s%s%s%s%s%s%s",one.name,one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
fseek(fp,offset,SEEK_SET);
printf("%ld",ftell(fp));
fprintf(fp,"%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s\n",one.name,one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
}
else
printf("\nsorry,no such one!");
fclose(fp);
}
void delete()
{
int m,k=0;
long offset1;
char namekey[8];
struct person one;
printf("\nenter name:");
scanf("%s",namekey);
if((fp=fopen(filename,"r+"))==NULL)
{
printf("\nfail!");
exit(1);
}
while(!feof(fp))
{
offset1=ftell(fp);
fscanf(fp,"%s%s%s%s%s%s%s%s\n",one.name,one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
if(!strcmp(namekey,one.name))
{
k=1;
break;
}
}
if(k)
{
printf("\nfind,here is:");
printf("\n%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s",one.name,one.id,one.sex,one.birth,one.prof,one.educat,one.salary,one.marriage);
printf("\nsure to del,enter 1;else,enter 0:");
scanf("%d",&m);
if(m)
{
fseek(fp,offset1,SEEK_SET);
fprintf(fp,"%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s\n","","","","","","","","");
}
}
else
printf("\nsorry,no such one!");
fclose(fp);
}