#include <stdio.h>
typedef struct s {
char name[20]; // char * name 这种方式声明, 后期诸多奇怪的问题, 比如 fseek的时候 取不到名字,不推荐在结构体中使用
int age;
float score;
} Student;
int main(int argc, const char * argv[]) {
FILE * fp = fopen("/Users/stone/Desktop/gg.data", "r");
if (fp != NULL) {
Student stu;
fseek(fp, sizeof(Student)*2, SEEK_SET);
fread(&stu, sizeof(Student), 1, fp);
printf("姓名:%s , 年龄:%d , 成绩:%.2f\n",stu.name,stu.age,stu.score);
} else {
printf("failed\n");
}
fclose(fp);
return 0;
}