4,012
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#define P12345 printf("%-5s%-8s%-20s%-8s%-8s%-12s%-10s\n","Num","Name","dept","duty","wage","mark","tot") ;
#define P56789 printf("%-5s%-8s%-20s%-8.2lf%-12s%-8s\n",info.Num,info.Name,temp1,info.wage,info.mark,info.tot);
enum Dept{ NG, logistics, Administration, humanresources, Financial}; /*部门 */
struct Info
{
char Num[5]; /* 序号 */
char Name[8]; /* 姓名 */
enum Dept dept; /* 部门 */
float wage; /* 工资 */
float price; /*奖金*/
char mark[12]; /* 备注 */
float tot; /* 总和 */
};
void menu();
int load() /*统计参数所指定的文件中的记录的个数的函数*/
{
struct Info info;
FILE *fp;
int i;
if((fp=fopen("data.dat","rb"))==NULL)
{
printf("\nCannot open file\n");
getchar();
return 0;
}
for(i=0;!feof(fp);i++)
fread(&info,sizeof(info),1,fp);
fclose(fp);
return(i-1); /*返回记录个数*/
}
void display() /* 职工信息显示函数 */
{
int amount; /* 信息文件中的记录总数 */
struct Info info;
FILE *fp1;
int total = 0;
char temp[10];
char temp1[10];
amount=load("inform.txt"); //首先说,这个地方就有错误了,你申请的load函数是没有参数的,但是你调用的时候却用了参数。
if((fp1=fopen("inform.txt","r+")) == NULL)
{
printf("\tCan not open the inform file!");
getchar();
exit(1);
}
P12345;
for(;total <amount;)
{
if(fread(&info, sizeof(info), 1, fp1) != 1)
{
printf("\nfile read wrong!\n");
getchar();
exit(1);
}
total++;
if(info.dept==Financial) strcpy(temp1,"Financial");
else if(info.dept==humanresources) strcpy(temp1,"humanresources");
else if(info.dept==Administration) strcpy(temp1,"Administration");
else if(info.dept==logistics) strcpy(temp1,"logistics");
else strcpy(temp1,"NG");
P56789;
if((total != 0) && (total%10 ==0))
{
printf("\n\n\tPress any key to continue......");
getchar();
puts("\n\n");
P12345;
}
}
fclose(fp1);
printf("\n\n\tThere are %d record in all!",total);
getchar();
}
main()
{
int amoment;
amoment=load();
printf("%d",amoment);
getchar();
display();
getchar();
}