| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 607 人关注过本帖
标题:[求助]我编的程序错在哪里?请看看!
只看楼主 加入收藏
xiehongyou
Rank: 1
等 级:新手上路
帖 子:84
专家分:0
注 册:2004-8-29
收藏
 问题点数:0 回复次数:0 
[求助]我编的程序错在哪里?请看看!

输入五个人的姓名和电话号码,把它们保存在C:\phone.dat,然后从这个文件全部读出显示在出来。这个程序错在那里? #include "stdio.h" struct phone /*定义结构型变量*/ {char name; long num; } pho[5];

void save()/*定义保存文件的函数*/ {FILE *fp; int i; if((fp=fopen("c:\phone123.dat","wb"))==NULL) {printf("cannot open file1!\n"); return; } for(i=0;i<5;i++) if(fwrite(&pho[i],sizeof(struct phone),1,fp)!=1) printf("file write error!"); }

void read()/*定义读文件的函数*/ { FILE *fp; int i; if((fp=fopen("c:\phone123.dat","rb"))==NULL) {printf("cannot open file2!\n"); return; } for(i=0;i<5;i++) {if(fread(&pho[i],sizeof(struct phone),1,fp)!=1) printf("file read error!\n"); printf("%s-4%4ld",pho[i].name,pho[i].num);/*边读边输出*/ }

} main()/*主函数*/ {int h; for(h=0;h<5;h++) scanf("%s%ld",pho[h].name,&pho[h].num);/*输入姓名和号码*/ save();/*调用函数*/ read();/*调用函数*/

getch(); }

搜索更多相关主题的帖子: include return cannot write 
2004-12-04 22:09
快速回复:[求助]我编的程序错在哪里?请看看!
数据加载中...
 
   



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

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