结构体
struct Student {
char name[32];
int score;
};
struct Student s = {"小明", 92};
printf("%s %d\n", s.name, s.score);
printf("%s %d\n", (&s)->name, (&s)->score); // 指针用 ->
文件读写
FILE *fp = fopen("note.txt", "w");
if (!fp) { printf("打开失败\n"); return 1; }
fprintf(fp, "score=%d\n", s.score);
fclose(fp);
fp = fopen("note.txt", "r");
char buf[128];
while (fgets(buf, sizeof(buf), fp)) printf("%s", buf);
fclose(fp);
打开模式:r 读、w 写(覆盖)、a 追加;操作完必须 fclose。