链表写入文件出错
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct stu
{
char name[10];
char age[3];
char phone[10];
struct stu *next;
};
struct stu *head,*pf,*pb;
FILE *fp;
int n,i;
void main()
{
pb=(struct stu*)malloc(sizeof(struct stu));
printf("the number:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nname:");
scanf("%s",&pb->name);
printf("\nage:");
scanf("%s",pb->age);
printf("\nphone:");
scanf("%s",pb->phone);
if(i==0)
head=pf=pb;
else
pf->next=pb;
pb->next=NULL;
pf=pb;
}
if((fp=fopen("report","wb"))==NULL)
{
printf("error");
exit(0);
}
fwrite(head,sizeof(struct stu),n,fp);
fclose(fp);
}
把结构体元素都设成字符串了