[求助]关于文件存储的问题
下列是一个管理系统的输入和存储部分,请高手帮忙看下我的这个为什么存储错误。我用文档打开存储的文件,里面是乱码,改成以W形式输入也不行。是不是使用的存储函数错误?请教下大家像学生管理系统存储信息的建立和使用一般用什么函数?下面程序可能运行一下更能找出我的错误吧。编写环境是TC2.0(初学,不敢用VC)。谢谢大家看完我的帖子。#include<stdio.h>
#include<malloc.h>
#include <string.h>
#define NULL 0
#define len sizeof(struct student)
struct student
{long num;
char name[20];
float msco;
float csco;
float esco;
struct student *next;
};
int n;
struct student *creat()
{
struct student *head;
struct student *p1,*p2;
n=0;
do
{
p1=(struct student *)malloc(len);
printf("please input the number of the student:");
scanf("%ld",&p1->num);
if(p1->num==0)break;
printf("please input the name of the student:");
scanf("%s",&p1->name);
printf("please input the math of the student:");
scanf("%f",&p1->msco);
printf("please input the cprogram of the student:");
scanf("%f",&p1->csco);
printf("please input the english of the student:");
scanf("%f",&p1->esco);
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
}while(p1->num!=0);
p2->next=NULL;
return(head);
}
void save(struct student *head)
{
FILE *fp;
struct student *p;
fp=fopen("stu_list","wb");
p=head;
if(head!=NULL)
do
{
fwrite(p,len,1,fp);
p=p->next;
}while(p!=NULL);
fclose(fp);
}
main()
{
long del_num;
float arg,*point=&arg;
struct student *head;
clrscr();
head=creat();
save(head);
}