帮个忙,为什么这函数不能循环进行??
struct student
{char num[15];
char name[20];
char sex;
int sorce[5];
struct student *next;};
struct student *bulid(void)
{struct student stu,*head,*p1,*p2;char a[15]={"ok"};
head=NULL;n=0;
p2=p1=(struct student *)malloc(LX);
{printf("Input the number:\nnum=");
scanf("%s",p1->num);
printf("Input the name:\nname:");
scanf("%s",p1->name);
printf("Input the sex:\nsex:");
getchar();p1->sex=getchar();
printf("Input the sorce:\nsorce=");
scanf("%s",p1->sorce); }
while(n<6);
{n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(LX);
{printf("Input the number:\nnum=");
scanf("%s",p1->num);
printf("Input the name:\nname:");
scanf("%s",p1->name);
printf("Input the sex:\nsex:");
getchar();p1->sex=getchar();
printf("Input the sorce:\nsorce=");
scanf("%s",p1->sorce);} }
p2->next=NULL;
return head;}
为什么????
下面这个可以???
struct stu
{long num;
float sorce;
struct stu *next;}*head,*p1,*p2;
int n;
struct stu *creat(void)
{
n=0;
p1=p2=(struct stu *)malloc(sizeof(struct stu));
scanf("%ld,%f",&p1->num,&p1->sorce);
head=0;
while(p1->num!=0)
{n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;p1=(struct stu *)malloc(sizeof(struct stu));
scanf("%ld,%f",&p1->num,&p2->sorce);}p2->next=0;
return head; }