从文件中读简单结构体数据
2009-06-18 16:02
176 查看
#include <stdio.h>
struct time
{
int num;
int year;
int month;
};
int main()
{
FILE *fp1;
FILE *fp2;
struct time t1;
fp1=fopen("in.dat", "r");
fp2=fopen("out.dat", "w");
fscanf(fp1, "%d %d %d", &(t1.num),
&(t1.year), &(t1.month));
fprintf(fp2, "%d %d %d", t1.num,
t1.year, t1.month );
printf("two file contents are:%d %d %d/n", t1.num,
t1.year, t1.month );
fclose(fp1);
fclose(fp2);
return 0;
}
复杂结构体,比如结构体套结构体,怎么读?思考~~~~~~~~~~
struct time
{
int num;
int year;
int month;
};
int main()
{
FILE *fp1;
FILE *fp2;
struct time t1;
fp1=fopen("in.dat", "r");
fp2=fopen("out.dat", "w");
fscanf(fp1, "%d %d %d", &(t1.num),
&(t1.year), &(t1.month));
fprintf(fp2, "%d %d %d", t1.num,
t1.year, t1.month );
printf("two file contents are:%d %d %d/n", t1.num,
t1.year, t1.month );
fclose(fp1);
fclose(fp2);
return 0;
}
复杂结构体,比如结构体套结构体,怎么读?思考~~~~~~~~~~
相关文章推荐
- 文件读写最简单的方法(附完整双精度浮点型数据向IEEE754型数据转换的原码)
- 在文件中加入数据的简单案例
- Python文件数据简单处理
- oracle 10g数据文件的表空间简单扩展
- SequenceInputStream类的简单介绍。以及用该类合并集合文件数据的程序代码。
- ASP.NET基础04_简单数据绑定与App_Offline.htm文件
- 简单方法获取数据连接的字符串(UDL文件)
- 编程珠玑学习笔记(1):简单磁盘文件数据排序
- C++ 简单读写文本文件、统计文件的行数、读取文件数据到数组
- Servlet 通过表单上传文件和获取表单数据的最简单方式
- 用Java简单的读取pdf文件中的数据
- 简单的写数据到txt文件
- 文件操作简单举例,从文件读数据,排好序,输出到另一个文件
- 一个简单但详细的解释Windows文件映射读取数据文件的例子
- 修复DBF数据表文件的简单方法
- Spark Shuffle六大问题 fetch操作、数据存储、文件个数、什么排序算法简单介绍
- C++ 简单读写文本文件、统计文件的行数、读取文件数据到数组
- C++ 简单读写文本文件、统计文件的行数、读取文件数据到数组
- Delphi基础Write写入结构体到文件(使用 file of myrecord就行了,真简单)
- 字符设备驱动1:新的方式添加cdev + 在open函数中将文件私有数据指向设备结构体