c 文件编程结果不对
#include<stdio.h>struct student
{
char name[20];
int age;
int num;
}stud[3];
void save()
{
FILE *fp;
int i;
if((fp=fopen("stu.c","wr"))==NULL)
{ printf("cannot open file\n");
return; }
for(i=0;i<3;i++)
if(fwrite(&stud[i],sizeof(struct student),1,fp)!=1)
{
printf("file write error\n");
fclose(fp);
}
if(i==3)fclose(fp);
}
void main()
{
int i=0;
for(i=0;i<3;i++)
{scanf("%s%d%d",stud[i].name ,&stud[i].age ,&stud[i].num );}
save();
}
编译是输入的 xiaomei 12 1
xiaozhang 12 2
xiaoqiang 13 3
在stu.c的文件中查看的时候是 xiaomei xiaozhang xiaoqiang
没有输出岁数和学号!这是为什么啊,求高手指点!