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

#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,File,include,FP)