创建链表后不能结束???求解
#include<stdio.h>#include<stdlib.h>
struct student
{
int num;
char s;
student *next;
};
student * creat()
{
student *pnew,*pend;
student *phead ;
phead=NULL;
do
{
pnew=new student;
printf("please input :\n");
printf("num:");
scanf("%d",&pnew->num);
char ch=getchar();
if(pnew->num==0) break;
printf("s:");
scanf("%c",&pnew->s);
if(phead==NULL) phead=pnew;
else pend->next=pnew;
pend=pnew;
}while(pnew->num!=0);
pend->next=0;
free(pnew);
return phead;
}
student * save(student *phead)
{
FILE *fp;
student *pn;
pn=phead;
if((fp=fopen("stud","w"))==NULL)
{
printf("cannot open file!\n");
exit(0);
}
do
{
fwrite(pn,sizeof(student),1,fp);
pn=pn->next;
}while(pn->next!=NULL);
return phead;
}
void main()
{
student *head;
head =creat();
save(head);
}
在创建中出现了问题,不能正常运行。。。。。