帮小弟找下错误
#include"stdio.h"#include"string.h"
#include"stdlib.h"
#define N 100
struct data {int y,m,d;};
struct staff
{char num[10];
char name[20];
char sex[20];
struct data birthday;
char xueli[20];
long wage;
char adress[50];
char telephone[30];
}st[N];
void menu()
{int n;
printf("\n\n");
printf("\t\t----------------------------\n");
printf("\t\t1----enter new data\n");
printf("\t\t2----output data\n");
printf("\t\t3----query information\n");
printf("\t\t4----modify the information\n");
printf("\t\t5----delete information\n");
printf("\t\t6----exit\n");
printf("\t\t----------------------------\n");
printf("enter your choice:");
scanf("%d",&n);
switch(n)
{case 1:enter();
case 2:output();
case 6:exit(0);
}
}
void save(n)
{FILE *fp;
int i;
if((fp=fopen("C:\\staff_information.txt","wb"))==NULL)
{printf("Cannot open this file\n");
return;}
for(i=0;i<n;i++)
if(fwrite(&st,sizeof(struct staff),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
enter()
{int i,j;
printf("how many people dou you want input?");
scanf("%d",&i);
for(j=1;j<=i;j++)
{printf("enter the %d people",j);
printf("\nnum:");scanf("%s",st[j].num);
printf("\nname:");scanf("%s",st[j].name);
printf("\nsex:");scanf("%s",st[j].sex);
printf("\nbirthday:");scanf("%d%d%d",&st[j].birthday.y,&st[j].birthday.m,&st[j].birthday.d);
printf("\nxueli:");scanf("%s",st[j].xueli);
printf("\nwage:");scanf("%ld",&st[j].wage);
printf("\nadress:");scanf("%s",st[j].adress);
printf("\ntelephone:");scanf("%s",st[j].telephone);
}
save(i);
menu();
}
output()
{FILE *fp;
int i,j;
if((fp=fopen("C:\\staff_information.txt","rb"))==NULL)
{printf("\nCannot open file\n");
return NULL;
}
for(i=0;!feof(fp);i++)
fread(&st[i],sizeof(struct staff),1,fp);
fclose(fp);
printf("\nnum name sex birthday xueli wage adress telephone\n");
for(j=0;j<=i;j++)
printf("%7s%7s%7s%4d%2d%2d%7s%7ld%7s%7s\n",st[j].num,st[j].name,st[j].birthday.y,st[j].birthday.m,st[j].birthday.d,
st[j].xueli,st[j].wage,st[j].adress,st[j].telephone);
menu();
}
main()
{menu();}
这是小弟编的一个管理系统的一部分。。检测没错误。。但运行起来 读取文件内容然后显示的时候显示不出。。请各位帮小弟看看~~~