📄 workin.c
字号:
if(info.education==doctor) strcpy(temp1,"doctor");
else if(info.education==master) strcpy(temp1,"master");
else if(info.education==college) strcpy(temp1,"college");
else if(info.education==junior) strcpy(temp1,"junior");
else strcpy(temp1,"high");
printf("%-5s%-8s%-8s%-4d/%-2d/%-2d%-10s%-8s%-8.2lf%-12s%-8s\n",info.num,info.name,temp,info.birthday.year,info.birthday.month,info.birthday.day,temp1,info.duty,info.wage,info.addr,info.phone);
if((total != 0) && (total%10 ==0))
{
printf("\n\n\tPress any key to continue......");
getch();
puts("\n\n");
printf("%-5s%-8s%-8s%-11s%-10s%-8s%-8s%-12s%-8s\n","nun","name","sex ","birthday","education","duty","wage","address","phone");
}
}
else if(flag1==2 && info.wage<value)
{
total++;
if(total == 1)
printf("%-5s%-8s%-8s%-11s%-10s%-8s%-8s%-12s%-8s\n","nun","name","sex ","birthday","education","duty","wage","address","phone");
if(info.sex==male)
strcpy(temp,"male");
else
strcpy(temp,"female");
if(info.education==doctor) strcpy(temp1,"doctor");
else if(info.education==master) strcpy(temp1,"master");
else if(info.education==college) strcpy(temp1,"college");
else if(info.education==junior) strcpy(temp1,"junior");
else strcpy(temp1,"high");
printf("%-5s%-8s%-8s%-4d/%-2d/%-2d%-10s%-8s%-8.2lf%-12s%-8s\n",info.num,info.name,temp,info.birthday.year,info.birthday.month,info.birthday.day,temp1,info.duty,info.wage,info.addr,info.phone);
if((total != 0) && (total%10 ==0))
{
printf("\n\n\tPress any key to continue......");
getch();
puts("\n\n");
printf("%-5s%-8s%-8s%-11s%-10s%-8s%-8s%-12s%-8s\n","nun","name","sex ","birthday","education","duty","wage","address","phone");
}
}
}
fclose(fp);
}
else /* 按学历进行查询 */
{
i=0;
do
{
printf("Please input the education degree you want to search:");
gets(degree);
if(!strcmp(degree,"doctor")) grade1=doctor;
else if(!strcmp(degree,"master")) grade1=master;
else if(!strcmp(degree,"college")) grade1=college;
else if(!strcmp(degree,"junior")) grade1=junior;
else if(!strcmp(degree,"high")) grade1=high;
else { printf("\nThe education value is illegimate....\n"); i=1; }
}while(i==1);
if((fp=fopen("inform.txt","rb")) == NULL)
{
printf("\tCan not open the inform file!");
getch();
exit(1);
}
total=0; /* 符合条件的记录数 */
for(con=0; con<amount; con++)
{
if(fread(&info, sizeof(info), 1, fp) != 1)
{
printf("\nfile read wrong!\n");
getch();
exit(1);
}
if(info.education == grade1)
{
total++;
if(total == 1)
printf("%-5s%-8s%-8s%-11s%-10s%-8s%-8s%-12s%-8s\n","nun","name","sex ","birthday","education","duty","wage","address","phone");
if(info.sex==male)
strcpy(temp,"male");
else
strcpy(temp,"female");
if(info.education==doctor) strcpy(temp1,"doctor");
else if(info.education==master) strcpy(temp1,"master");
else if(info.education==college) strcpy(temp1,"college");
else if(info.education==junior) strcpy(temp1,"junior");
else strcpy(temp1,"high");
printf("%-5s%-8s%-8s%-4d/%-2d/%-2d%-10s%-8s%-8.2lf%-12s%-8s\n",info.num,info.name,temp,info.birthday.year,info.birthday.month,info.birthday.day,temp1,info.duty,info.wage,info.addr,info.phone);
if((total != 0) && (total%10 ==0))
{
printf("\n\n\tPress any key to continue......");
getch();
puts("\n\n");
printf("%-5s%-8s%-8s%-11s%-10s%-8s%-8s%-12s%-8s\n","nun","name","sex ","birthday","education","duty","wage","address","phone");
}
}
}
fclose(fp);
}
printf("\n\n\tThere are %d record included!",total);
getch();
menu();
}
void modify() /* 信息修改函数*/
{
struct Node
{
char num[10];
struct Node * next;
};
int amount; /* 信息文件中的记录总数 */
int con=0; /* 已处理的文件记录总数 */
struct Node node;
struct Node * head=NULL, * pf=NULL, * pb=NULL;
struct Info info, info_temp;
FILE * fp;
int total=0;
long offset=0; /* 文件位置指针偏移量 */
char temp[10], temp1[10];
int flag=0; /* 指示是否继续进行修改,为1时继续 */
char ID[10]; /* 待修改的记录的职工号 */
int ord; /* 待修改的项目指示 */
int repeat; /* 在修改中用于重复的输入 */
int Yes=0; /* 指示是否保存修改 */
char choice;
amount=load("inform.txt");
if((fp=fopen("inform.txt","rb")) == NULL)
{
printf("\tCan not open the inform file!");
getch();
exit(1);
}
printf("\n%-5s%-8s%-8s%-11s%-10s%-8s%-8s%-12s%-8s\n","nun","name","sex ","birthday","education","duty","wage","address","phone");
for(con=0; con<amount; con++)
{
if(fread(&info, sizeof(info), 1, fp) != 1)
{
printf("\nfile read wrong!\n");
getch();
exit(1);
}
pb=(struct Node *)malloc(sizeof(struct Node)); /* 创建包含num信息的链表,用于后续的查找 */
strcpy(pb->num,info.num);
if(total==0)
head=pf=pb;
else
pf->next=pb;
pb->next=NULL;
pf=pb;
total++;
if(info.sex==male)
strcpy(temp,"male");
else
strcpy(temp,"female");
if(info.education==doctor) strcpy(temp1,"doctor");
else if(info.education==master) strcpy(temp1,"master");
else if(info.education==college) strcpy(temp1,"college");
else if(info.education==junior) strcpy(temp1,"junior");
else strcpy(temp1,"high");
printf("%-5s%-8s%-8s%-4d/%-2d/%-2d%-10s%-8s%-8.2lf%-12s%-8s\n",info.num,info.name,temp,info.birthday.year,info.birthday.month,info.birthday.day,temp1,info.duty,info.wage,info.addr,info.phone);
if((total != 0) && (total%10 ==0))
{
printf("\n\n\tPress any key to continue......");
getch();
puts("\n\n");
}
}
fclose(fp);
do
{
printf("\nPlease enter the num that you want to modify:");
gets(ID);
pf=head;
offset=0l;
while(strcmp(pf->num,ID) && pf->next!=NULL)
{
pf=pf->next;
offset++;
}
if(!strcmp(pf->num,ID)) /* 待修改的记录存在 */
{
if((fp=fopen("inform.txt","rb+"))==NULL)
{
printf("\n\nfile open wrong!");
getch();
exit(1);
}
offset *= sizeof(struct Info); /* 使文件位置指针移动到待修改记录处 */
rewind(fp);
if(fseek(fp, offset, 0) != 0)
{
printf("\n\nfile operation wrong !");
getch();
exit(1);
}
fread(&info, sizeof(info), 1, fp);
fseek(fp,(long)(-1)*sizeof(struct Info), 1); /* 使文件位置指针返回到待修改记录处 */
printf("\nthe record you want to modify is:\n");
printf("%-5s%-8s%-8s%-11s%-10s%-8s%-8s%-12s%-8s\n","nun","name","sex ","birthday","education","duty","wage","address","phone");
printf("%-5s%-8s%-8s%-4d/%-2d/%-2d%-10s%-8s%-8.2lf%-12s%-8s\n",info.num,info.name,temp,info.birthday.year,info.birthday.month,info.birthday.day,temp1,info.duty,info.wage,info.addr,info.phone);
do
{
printf("\n\nyou can modify by:1).num\t2).name\t3).sex\t4).birthday\t5).education");
printf("\n\t6).duty\t7).wage\t8).address\t9).phone\t10).all data\t11).cancel and back");
printf("\nWhich item you need to modify: [ ]\b\b");
scanf("%d", &ord);
}while(ord>11 || ord<1);
switch(ord)
{
case 1: printf("\nnum:");
repeat=0;
do
{
gets(ID); getchar();
pb=head;
while(strcmp(pb->num,ID) && pb->next !=NULL)
pb=pb->next;
if(!strcmp(pb->num,ID))
printf("\nError:the num is already exist, please input again...");
repeat=1;
}while(repeat);
strcpy(info.num, ID);
break;
case 2: printf("\nname:");gets(info.name); getchar(); break;
case 3: printf("\nsex:"); gets(temp); getchar();
if(!strcmp(temp,"male")) info.sex=male;
else if(!strcmp(temp,"female")) info.sex=female;
else printf("\ninput error! Can not modify the record ...");
break;
case 4: printf("\nbirthday(yyyy/mm/dd):");scanf("%d/%d/%d",&info.birthday.year,&info.birthday.month,&info.birthday.day);
getchar(); break;
case 5: printf("\neducation:"); gets(temp); getchar();
if(!strcmp(temp,"doctor")) info.education=doctor;
else if(!strcmp(temp,"master")) info.education=master;
else if(!strcmp(temp,"college")) info.education=college;
else if(!strcmp(temp,"junior")) info.education=junior;
else if(!strcmp(temp,"high")) info.education=high;
else printf("\ninput error! Can not modify the record...");
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -