| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 844 人关注过本帖
标题:链表中的东西写到文件中读出来的问题
取消只看楼主 加入收藏
gxppa2006
Rank: 1
等 级:新手上路
帖 子:178
专家分:0
注 册:2007-2-27
收藏
 问题点数:0 回复次数:0 
链表中的东西写到文件中读出来的问题
#include <stdio.h>
#include <malloc.h>
typedef struct wage_info
{
char name[20];
char department[100];
float base_pay;
float allowance;
float total;
struct wage_info *next;
}wage;
main()
{
wage *head,*p,*s;
FILE *fp;
float c;
if((fp=fopen("paydata","a+"))==NULL)
{
printf("file is not exist.\n");
fp=fopen("paydata","wb");
}
fp=fopen("paydata","a+");
head=(wage *)malloc(sizeof(wage));
p=head;
printf("Please input the name department base_pay allowance,ends with name is 0:\n");
do
{
s=(wage *)malloc(sizeof(wage));
scanf("%s,%s,%f,%f",&s->name,&s->department,&s->base_pay,&s->allowance);
c=(s->base_pay)+(s->allowance);
printf("%s %s %f %f %f",s->name,s->department,s->base_pay,s->allowance,c);
p->next=s;
p=s;
}while(p->base_pay!=0);
p->next=NULL;
head=head->next;
free(p);
if(fwrite(head,sizeof(wage),1,fp)!=1)
{
printf("can not write files!\n");
}
fclose(fp);
fp=fopen("paydata","rb");
fread(head,sizeof(wage),1,fp);
fclose(fp);
getch();
}
搜索更多相关主题的帖子: 链表 wage float 文件 
2007-04-14 23:29
快速回复:链表中的东西写到文件中读出来的问题
数据加载中...
 
   



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

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