您的位置:首页 > 其它

从文件中读简单结构体数据

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;
}

复杂结构体,比如结构体套结构体,怎么读?思考~~~~~~~~~~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: