程序运行时怎么只能输入一条记录,就停住了。帮忙看看
#include "stdio.h"#include "conio.h"
#define NULL 0
#define LEN sizeof(struct student)
struct student
{char num[6];
char name[8];
struct student *next;
};
struct student *creat(void)
{struct student *p1,*p2,*head;
int n=0;
p1=p2=(struct student *)malloc(LEN);
head=NULL;
printf("Input 0 to end.\n");
printf("Input num,name:\n");
scanf("%s,%s",&p1->num,&p1->name);
while(p1!=NULL)
{if(n==0)head=p1;
else p2->next=p1;
n++;
p2=p1;
}
p2->next=NULL;
return(head);
}
void print(struct student *p)
{while(p!=NULL)
{printf("%4s,%4s",p->num,p->name);
p=p->next;
}
}
main()
{struct student *ha,*hb;
ha=creat();
hb=creat();
print(ha);
getch();
}
程序运行时怎么只能输入一条记录,就停住了。