#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct Student
{
int num;
char name[10];
char sex[5];
int age;
}Student;
int main()
{
Student s;
FILE* f = fopen("student.dat", "w");
s.num = 0;
strcpy(s.name, "李四");
strcpy(s.sex, "女");
s.age = 20;
fputs(&s, f);
fclose(f);
f = fopen("student.dat", "r");
fgets(&s, 1, f);
printf("%d %s %s %d\n", s.num, s.name, s.sex, s.age);
fclose(f);
system("pause");
return 0;
}
将s中的数据一个一个fprintf()咯,fputs的输入是字符串,你那个Student *是自定义类型,肯定不能一次性输入进去噻