一个简单的C程序,怎么改能让它正确显示?

[复制链接]
查看11 | 回复2 | 2010-7-22 01:26:00 | 显示全部楼层 |阅读模式
#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");
}

回复

使用道具 举报

千问 | 2010-7-22 01:26:00 | 显示全部楼层
//已在VC6中编译通过,并正确运行!#include"stdio.h"#include"stdlib.h"#include"string.h"#define N 10int 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();v
回复

使用道具 举报

千问 | 2010-7-22 01:26:00 | 显示全部楼层
不知楼主是不是要这个效果:#include"stdio.h"#include"stdlib.h"#include"string.h"#define N 10int i;struct staff{int num;char name[10];char sex[10];charage[10];char pay[1
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行