C语言链表信息存入文件
存入之后,后半部分是一堆乱码。。。。case 1:head=creat();
enter(head);break;
case 2:printf("11") ;break;
case 3:printf("qqq");break;
case 4:printf("222");break;
case 5:display_information();break;
}
}
}
struct student *creat()//创建
{
int i=0,j=1;
char a;
struct student *phead;
struct student *r,*stu;
phead=(struct student *)malloc(sizeof(struct student ));
phead->next =NULL;
r=phead;
do{
stu=(struct student *)malloc(sizeof(struct student ));
printf("姓名:");
scanf("%s",stu ->name );
printf("学号:");
scanf("%s",stu ->numb );
printf("性别:");
scanf("%s",stu ->sex );
printf("年龄:");
scanf("%d",&stu ->age );
printf("成绩:");
scanf("%d",&stu ->grade);
j++;
r->next =stu;
r=stu;
printf("是否继续输入?Y/N\n");
a=getche();
}while(a=='Y'||a=='y');
r->next =NULL;
return(phead);
}
int enter(struct student *head)//输入文件(创建)
{
FILE *fp;
struct student *stu;
stu=head;
fp=fopen("f:\\test.txt","at");
while(stu!=NULL)
{
fprintf(fp,"%s %s %s %d %d\n",stu->name,stu->numb,stu->sex,&stu->age,&stu->grade);
stu=stu->next;
}
fclose(fp);
}
结果是这样
姓名:张三
学号:04181120
性别:男
年龄:19
成绩:99
是否继续输入?Y/N
n
5
?R_PROFILE_STRING=Default 10818552 10818568
张三 04181120男 男 10818648 108186 LE_STRING=Default 10818552 10818568
张三 04181120男 男 10818648 108186 G=Default 10818552 10818568
张三 04181120男 男 10818648 108186 10818936 10818952