在C语言中,可以使用fwrite函数将结构体写入文件。下面是一个示例: #include <stdio.h> struct Person { char name[20]; int age; float height; }; int main() { FILE *file = fopen("person.dat", "wb"); // 打开文件,以二进制写入方式打开 if (file == NULL) { printf("无法打开文件\n");...
1、以二进制写方式(wb)打开文件 2、调用写入函数fwrite()将结构体数据写入文件 3、关闭文件指针 相应的,读文件也要与之匹配:1、以二进制读方式(rb)打开文件 2、调用读文件函数fread()读取文件中的数据到结构体变量 3、关闭文件指针 参考代码如下:include<stdio.h>struct stu {char name[30];in...