![]() |
|
首页│注册│帮助 | |||
相关问题
| • | [求助]数据库调用问题 |
| • | [求助]求助考勤系统的程序 |
| • | [求助]编译器问题 |
| • | 郁闷啦 |
| • | [分享]新人报道到!。。大家好 |
| • | 【求助】数组和指针的长度 |
| • | 菜鸟求助版主额~ |
| • | [求助]关于一个嵌套类和有元的问题 |
待解决
[求助]我编的程序错在哪里?请看看!
<P>输入五个人的姓名和电话号码,把它们保存在C:phone.dat,然后从这个文件全部读出显示在出来。这个程序错在那里?
#include "stdio.h"
struct phone /*定义结构型变量*/
{char name;
long num;
} pho[5];</P>
<P>void save()/*定义保存文件的函数*/
{FILE *fp;
int i;
if((fp=fopen("c:phone123.dat","wb"))==NULL)
{printf("cannot open file1!
");
return;
}
for(i=0;i<5;i++)
if(fwrite(&pho[i],sizeof(struct phone),1,fp)!=1)
printf("file write error!");
}</P>
<P>void read()/*定义读文件的函数*/
{
FILE *fp;
int i;
if((fp=fopen("c:phone123.dat","rb"))==NULL)
{printf("cannot open file2!
");
return;
}
for(i=0;i<5;i++)
{if(fread(&pho[i],sizeof(struct phone),1,fp)!=1)
printf("file read error!
");
printf("%s-4%4ld",pho[i].name,pho[i].num);/*边读边输出*/
}</P>
<P>}
main()/*主函数*/
{int h;
for(h=0;h<5;h++)
scanf("%s%ld",pho[h].name,&pho[h].num);/*输入姓名和号码*/
save();/*调用函数*/
read();/*调用函数*/</P>
<P>getch();
}
</P>
提问者:xiehongyou 2004-12-04 22:09:00
答复

