大侠:谢谢你光顾我的程序,这程序已没错了,但是功能还是不能够完全显示出来,让小生见识下高手的利害
#include<conio.h>
#include<stdio.h>
#include<dos.h>
struct birth /*出生年月日结构定义*/
{
int year;
int month;
int day;
};
struct address
{
char address[60];
char mobile[13];
char family_tel[15];
char mail[25];
};
struct achieve
{
char degree[20];
char experience[1000];
};
struct worker
{
int number;
char name[20];
char sex;
char nation;
struct birth birth;
struct address address;
struct achieve achieve;
}workers[20];
FILE*fp;
int a;
void Data_load()
{
int b;
long c;
fp=fopen("worker.txt","r+t") ;
if(fp!=NULL)
{
for(a=1;a<20;a++)
{
if(fgetc(fp)==EOF)
return;
c=a-1;
fseek(fp,c*sizeof(struct worker),SEEK_SET);
fread(&workers[a],sizeof(struct worker),1,fp);
fclose(fp);
}
}
else
{
fp=fopen("worker.txt","w");
fclose(fp);
a=1;
}
}
void Data_Show(int b)
{
printf("\n\n\tNo:%3d\n",workers[b].number);
printf("\n\n\Name:%-20s\n\tsex:%c\n\tnation:%s\n",workers[b].name,workers[b].sex,workers[b].nation);
printf("\n\n\tBirthday(y/m/d):%4d%2d%2d",workers[b].birth.year,workers[b].birth.month,workers[b].birth.day);
printf("\n\n\tAddress:%-60s\n\tMobile:%13d\n\tFamily_tel:%15d\n\tmail:%-25s\n",workers[b].address.address,workers[b].address.mobile,workers[b].address.family_tel,workers[b].address.mail);
printf("\n\n\tDegree:%-20s\n\texperience:%-1000s\n",workers[b].achieve.degree,workers[b].achieve.experience);
getch();
}
void Data_Input(int b)
{
fflush(stdin);
workers[b].number=b;
printf("\n\n\tNo%d record",b);
printf("\n\n\tName");
scanf("%s",&workers[b].name);
getchar();
printf("\n\tnation:");
scanf("%s",&workers[b].nation);
getchar();
printf("\n\n\tsex(m/c):");
scanf("%c",&workers[b].sex);
getchar();
printf("\n\n\tbirthday:");
printf("\n\n\tyear:");
scanf("%c",&workers[b].birth.year);
printf("\n\n\tmonth:");
scanf("%d",&workers[b].birth.month);
printf("\n\n\tday:");
scanf("%d" ,&workers[b].birth.day);
printf("\n\n\t,address:");
scanf("%s",workers[b].address.address);
getchar();
printf("\n\n\tmobile:");
scanf("%c",&workers[b].address.mobile);
getchar();
printf("\n\n\tfamily_tel:");
scanf("%c",&workers[b].address.family_tel);
getchar();
printf("\n\n\tmail:");
scanf("%c", &workers[b].address.mail);
getchar();
printf("\n\n\tdegree:");
scanf("%s",&workers[b].achieve.degree);
getchar();
printf("\n\n\texperience:");
scanf("%s",&workers[b].achieve.experience);
}
void Data_Save()
{
int b;
fp=fopen("worker.txt","w");
for(b=1;b<=a;b++)
{
fwrite(&workers[b],sizeof(struct worker),1,fp);
}
fclose(fp);
}
main()
{
int b,c;
char ch,name[20];
char *search_name=name;
clrscr();
Data_load();
a--;
printf("\n\n\tFunction choose:");
printf("\n\t1.Read");
printf("\n\t2.Append");
printf("\n\t3.Delete");
printf("\n\t4.Search");
printf("\n\t5.Insert");
printf("\n\t6.Save and exit");
printf("\n\t7,Quit");
printf("\n\n");
printf("\t choice:");
scanf("%c",&ch);
switch(ch)
{
case '1':
b=1;
while(getch()!=0x1b&&b<=a) Data_Show(b++);
if(b>a)
printf("\n\tEnd of e_note\n");
break;
case '2':
while(getch()!=0x1b&&b<20)
{
a++;Data_Input(a);
}
if(a==20)
printf("\n\te_note is filled\n");
break;
case '3':
if(a<1)
{
printf("\n\tPlease Append record\n");
break;
}
printf("\n\t Dolete No:");
scanf("%d",&c);
for(b=c;b<a;b++)
{
strcpy(workers[b].name,workers[b+1].name);
strcpy(workers[b].sex,workers[b+1].sex);
strcpy(workers[b].nation,workers[b+1].nation);
strcpy(workers[b].birth.year,workers[b+1].birth.year);
strcpy(workers[b].birth.month,workers[b+1].birth.month);
strcpy(workers[b].birth.day,workers[b+1].birth.day);
strcpy(workers[b].address.address,workers[b+1].address.address);
strcpy(workers[b].address.mobile,workers[b+1].address.mobile);
strcpy(workers[b].address.family_tel,workers[b+1].address.family_tel);
strcpy(workers[b].address.mail,workers[b+1].address.mail);
strcpy(workers[b].achieve.degree[b+1],workers[b+1].achieve.degree);
strcpy(workers[b].achieve.experience,workers[b+1].achieve.experience);
}
a--;
break;
case'4':getchar();
printf("\n\t Please input name:");
gets(search_name);
for(b=0;b<=a;b++)
{
if(strcmp(search_name,workers[b].name)==0)
{
Data_Show(b);
break;
}
}
if(b>a)
{
printf("\n\t No such records");
}
break;
case '5':
printf("\n\tinsert No:");
scanf("%d",&c);
for(b=a+1;b>c;b--);
{
strcpy(workers[b].name,workers[b-1].name);
strcpy(workers[b].sex,workers[b-1].sex);
strcpy(workers[b].nation,workers[b-1].nation);
strcpy(workers[b].birth.year,workers[b-1].birth.year);
strcpy(workers[b].birth.month,workers[b-1].birth.month);
strcpy(workers[b].birth.day,workers[b-1].birth.day);
strcpy(workers[b].address.address,workers[b-1].address.address);
strcpy(workers[b].address.mobile,workers[b-1].address.mobile);
strcpy(workers[b].address.family_tel,workers[b-1].address.family_tel);
strcpy(workers[b].address.mail,workers[b-1].address.mail);
strcpy(workers[b].achieve.degree,workers[b-1].achieve.degree);
strcpy(workers[b].achieve.experience,workers[b-1].achieve.experience);
}
Data_Input(c);
a++;
Data_Save();
break;
case '6':
Data_Save();
exit(0);
break;
case '7':
printf("\n\t Do you want to save e_note:(y/n)");
ch=getch();
if(ch=='y')
{
Data_Save();
exit(0);
}
default: printf("please choose num 1-4\n");
}
}
请高手中的高手帮忙