#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#define N 10
int i;
struct staff
{
int num;
char name[10];
char sex[10];
charage[10];
char pay[10];
char degree[20];
char addr[10];
char phone[20];
}peo;
FILE *fp;
char file[20];
void shuru();
void output();
void main()
{
shuru();
output();
}
void in()
{
struct staff peo;
int i=0;
printf("姓名:\n");
scanf("%s",peo.name);
while(strcmp(peo.name,"#"))
{
peo.num=++i;
printf("姓名:\n");
scanf("%s",peo.name);
fprintf(fp,"%-10d%-10s%\n",peo.num,peo.name);
}
}
void shuru()
//输入函数
{
printf("请先创建文件名,注意要输入后缀:\n");
scanf("%s",file);
fp=fopen(file,"w+");
if(fp==NULL)
{
printf("不能打开文件\n");
exit(0);
}
fprintf(fp,"%-10s%-10s\n","编号","姓名");
printf("请输入职工信息,以#结束:\n");
in();
fclose(fp);
printf("\n\t\t信息已保存!,回到主菜单\n");
}
void output()
//显示函数
{
struct staff peo;
printf("显示信息");
if((fp=fopen(file,"r"))==NULL)
/*打开文件*/
{
printf("\n不能打开该文件!");
exit(0);
}
printf("\n\n%20s\n","职工信息管理系统\n\n");/*向文件输入数据*/
while(!feof(fp))
{
fscanf(fp,"%d,%s",peo.num,peo.name);
printf("%-10d%-10s",peo.num,peo.name);
}
fclose(fp);/*关闭文件*/
printf("1-修改职工信息。2-回到主菜单\n");
}
|