在线等待!急! 关于文件操作的!
下面一段代码,哪里有问题?
怎么运行结果就是不对!
#include <stdio.h>
#include <stdlib.h>
struct student
{
int no;
char name[10];
};
typedef struct student ST;
void main()
{
ST *st1;
ST *st2;
FILE *fp;
st1=(ST *)malloc(sizeof(ST));
st2=(ST *)malloc(sizeof(ST));
if(!(fp=fopen("学生信息.txt","w+")))
{
printf("打开文件失败!");
}
printf("请输入学生学号:");
scanf("%d",&st1->no);
printf("请输入学生姓名:");
scanf("%s",st1->name);
fwrite(st1,sizeof(ST),1,fp);
fread(st2,sizeof(ST),1,fp);
printf("学生学号为:%d,学生姓名为:%s",st2->no,st2->name);
free(st1);
free(st2);
st1=NULL;
st2=NULL;
fclose(fp);
}