这个程序怎样改呢?
#include<stdio.h>#include<malloc.h>
struct student
{
int num;
char name;
int age;
int sex;
struct student *link;
}stud;
creat(int n)
{
struct student *h,*p;
int i;
h=(struct student *)malloc(sizeof(stud));
if(h==NULL)
{
printf("not enough memory!");
return(0);
}
h=NULL;
for(i=0;i<=n;i++)
{
if((p=(struct student *)malloc(sizeof(stud)))==NULL)
{
printf("内存不足!");
return(0);
}
scanf("%d",&p->num);
scanf("%s",&p->name);
scanf("%d",&p->age);
scanf("%s",&p->sex);
p->link=h;
h=p;
}
void save(stud *h)
{
FILE *fP;
stud *p;
if((fp=fopen("d:\\123","w"))==NULL)
{
printf("can now open file!");
exit(1);
}
printf("\n saving file...\n");
p=h;
while(p!=NULL)
{
fwrite(p,sizeof(stud),1,fp);
p=p->next;
}
fclose(fp);
printf("*******save successful!********\n");
}
}
void main()
{
struct student *h;
h=(struct student *)creat(4);
save(h);
}