#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>
struct Test
{
int a;
char c;
};
int main()
{
FILE* fp;
struct Test data={100,'a'};
struct Test data2;
fp=fopen("./file1","w+");
int n_write=fwrite(&data,sizeof(struct Test),1,fp);
fseek(fp,0,SEEK_SET);
int n_read=fread(&data2,sizeof(struct Test),1,fp);
printf("read %d,%c\n",data2.a,data2.c);
fclose(fp);
return 0;
}
309__15.标准c库写入结构体到文件
最新推荐文章于 2024-10-30 13:57:55 发布