我用DEV写入了一些数据,在另存为的时候保存为“All Files”,并且把后缀名改为了.dat(系统是Windows 11 家庭版)。但是当我尝试用fread函数读取符合struct大小的第一组数据,输出以及存储为文本文件时,发现可以正常读出char类型的数据,但是不可以读出int类型的数据。请问这是为什么?
图为用VS code打开二进制文件的情况
图为源代码和运行时打印的a的情况


最后的是输出的文件内的情况
最后是代码
#include <stdio.h>
#include <stdlib.h>
#define LEN sizeof(struct student)
typedef struct student
{
int ID;
char course;
int score;
} STUD;
int main()
{
FILE* in = fopen("D:\\Untitled1.dat","rb");
if (in == NULL)
{
printf("no such file(student.data).\n");
exit(1);
}
STUD a;
fread(&a, LEN, 1, in);
printf("%d,%c,%d", a.ID, a.course, a.score);
fclose(in);
FILE* out = fopen("D:\\output.txt", "w");
if (out == NULL)
{
printf("no such file(output.txt).\n");
exit(1);
}
fprintf(out, "%d,%c,%d\n", a.ID, a.course, a.score);
fclose(out);
return 1;
}