C语言写文件,记事本打开是乱码

程序输入之后,记事本只显示name、addr,而int型数据均为乱码,请问如何解决这一问题??

#include
#define SIZE 3

struct Student_type
{
char name[10];
int num;
int age;
char addr[15];
}stud[SIZE];

void save()
{
FILE * fp;
int i;
if((fp=fopen("stu.dat","wb"))== NULL) /**< 注意括号的数量 */
{
printf("cannot open the file\n");
return;
}
for(i=0;i<SIZE;i++)
if(fwrite(&stud[i],sizeof(struct Student_type),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}

int main()
{
int i;
printf("please enter data of students:\n");
for(i=0;i<SIZE;i++)
scanf("%s%d%d%s",stud[i].name,&stud[i].num,&stud[i].age,stud[i].addr);
save();
return(0);
}

图片说明

我去,你咋把内存中的结构体直接拷到文件中了?内存里的数据是结构化了的数据,而文件中的是序列化之后的数据,不一样的呀。。。

http://blog.csdn.net/shen_001/article/details/53786716

fwrite(&stud[i], sizeof(Student_type), 1, fp) 问题在这里,分开写~

楼上说得对。写进文件中的应该是字符串,无论你在程序中是什么类型的变量,最终都要将结果转换成字符串。