| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 392 人关注过本帖
标题:帮小弟找下错误
只看楼主 加入收藏
爱shi浅浅
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-7-14
结帖率:100%
收藏
 问题点数:0 回复次数:2 
帮小弟找下错误
#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();}
  这是小弟编的一个管理系统的一部分。。检测没错误。。但运行起来 读取文件内容然后显示的时候显示不出。。请各位帮小弟看看~~~
搜索更多相关主题的帖子: telephone include 
2010-07-18 12:48
sunyh1999
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:14
帖 子:1178
专家分:3032
注 册:2009-5-17
收藏
得分:0 
你的menu函数中的switch处就有问题了:
  switch(n)
  {case 1:enter();//都应该加上break;
   case 2:output();
   case 6:exit(0);
  }
}


欢迎来到我的博客:http://blog..cn/noisunyuhong
2010-07-18 13:08
爱shi浅浅
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-7-14
收藏
得分:0 
我改了。。但那个文件输出还是没法输出
2010-07-18 13:15
快速回复:帮小弟找下错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014728 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved