C语言可以用fread函数从文件中读取一个数据块,fwrite函数向文件写一个数据块。将数据原封不动的写入到磁盘上。以二进制的形式。

fread(buffer ,size,count,fp);

fwrite(buffer ,size,count,fp);

现在有一个结构体 struct Student{...........} student1;想将它写入磁盘上保存下来。

有一个data.txt 空文件 。

FILE *p2file;

p2file = fopen("data.txt","wb");

fwrite(&student1,sizeof(student),p2file);fclose(p2file);

-------------------------------------------------------

现在data.txt已经有了一个数据,用fread读出来。

FILE *p2file;

p2file = fopen("data.txt","rb");

fread(&student1,sizeof(student1),1,p2file);

printf('name is %s',student.name);

相关文章:

  • 2021-09-30
  • 2023-04-03
  • 2021-07-01
  • 2021-07-10
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-21
相关资源
相似解决方案