- 分享
- 0
- 人气
- 0
- 主题
- 0
- 帖子
- 11
- UID
- 262091
- 积分
- 11
- 阅读权限
- 11
- 注册时间
- 2009-9-9
- 最后登录
- 2009-9-23
- 在线时间
- 5 小时
|
回复 #2 Super-Tomato 的帖子
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{int*a,*b,*ahead,*bhead,temp,*Salary;
FILE*fp1;
char name[10],post[25];int id,branch,salary,op=1;
fp1=fopen("salary_A.txt","w");
while(op==1)
{
printf("enter name, id, post, branch and salary:");
scanf("%s%d%s%d%d",&name,&id,&post,&branch,&salary);
fprintf(fp1,"%s\t%d\t%s\t\t%d\t%d\n",name,id,post,branch,salary);
printf("Enter 1 to continue:");
scanf("%d",&op);
}
fclose(fp1);
FILE*fp2;
fp2=fopen("salary_B.txt","w");
while(op==1)
{
printf("enter name, id, post, branch and salary:");
scanf("%s%d%s%d%d",&name,&id,&post,&branch,&salary);
fprintf(fp2,"%s\t%d\t%s\t\t%d\t%d\n",name,id,post,branch,salary);
printf("Enter 1 to continue:");
scanf("%d",&op);
}
fclose(fp2);
FILE*fp3;
int option;
fp2=fopen("salary_B.txt","r");
fp1=fopen("salary_A.txt","r");
fp3=fopen("salary_AB.txt","w+");
if(fp1==NULL||fp2==NULL){
printf("error in opening file\n");
return 1;
}
ahead=bhead=NULL;
while(!feof(fp1))
{
temp=(Salary*)malloc(sizeof(Salary));
fscanf(fp1,"%s%d%s%s%s\n",temp->name,temp->id,temp->post,temp->branch,temp->sal);
temp->next=NULL;
if(ahead==NULL)
{
*a=temp;
*ahead=*a;
}
else
{
a->next=temp;
*a=temp;
}
while(!feof(fp2))
{
temp=(Salary*)malloc(sizeof(Salary));
fscanf(fp2,"%s%d%s%s%s\n",temp->name,temp->id,temp->post,temp->branch,temp->sal);
temp->next=NUll;
if(bhead==NULL)
{
*b->next=temp;
*bhead=*b;
}
}
*a=*ahead;
*b=*bhead;
while(a!=NULL||b!=NULL)
{
if(a!=NULL)
{
fprintf(fp3,"%s\t%d%s%s%s\n",a->name,a->id,a->post,a->branch,a->sal);
a=a->next;
}
else if(b!=NULL)
{
fprintf(fp3,"%s\t%d%s%s%s\n",b->name,b->id,b->post,b->branch,b->sal);
b=b->next;
}
}
int option=1; while (option!=5)
{
printf("-----------\n");
printf("SALARY MENU\n");
printf("-----------\n");
printf("1. TO LIST CLERK\n");
printf("2. TO LIST ENGINEERS\n");
printf("3. TO LIST MANAGERS\n");
printf("4. TO EXIT\n");
printf("-----------\n");
printf("PLEASE ENTER YOUR OPTION <1/2/3/4>");
scanf("%d",&option);
a=ahead;
b=bhead;
fseek(fp3,0,SEEK_SET);
switch(option){
case 1:
&salary);
while(!feof(fp3)){
fscanF(fp3,"%s%s%s%s%s",a->name,a->id,a->post,a->branch,a->sal);
if(strcmp(a->des,"Clerk")==0)
printf("%10s%10d%10s%10s%10f\n",a->name,a->id,a->post,a->branch,a->sal);
}
break;
case 2:
while(!feof(fp3)){
fscanF(fp3,"%s%s%s%s%s",a->name,a->id,a->post,a->branch,a->sal);
if(strcmp(a->post,"Engineer")==0)
printf("%10s%10d%10s%10s%10f\n",a->name,a->id,a->post,a->branch,a->sal);
}
break;
case 3:
while(!feof(fp3)){
fscanF(fp3,"%s%s%s%s%s",a->name,a->id,a->post,a->branch,a->sal);
if(strcmp(a->des,"manager")==0)
printf("%10s%10d%10s%10s%10f\n",a->name,a->id,a->post,a->branch,a->sal);
}
break;
case 4:
printf("Thank you!!\n");
return 0;
break;
default:
printf("invalid input,please enter option again\n");
break;
}
fclose(fp3);
return 0;
}
我就写到这里~但error弄不走~ |
|