如何把malloc函数和链表和for循环语句结合起来

如题所述

第1个回答  2012-05-04
Student*creat()//创建链表
{
int n=0;//记录结点
Student*head,*p1,*p2;
head=p1=p2=(Student*)malloc(LEN);
scanf("%d%s%f",&p1->num,p1->name,&p1->score);
for(n=1;p1->num!=0;n++)
{
p2->next=p1;
p2=p1;
p1=(Student*)malloc(LEN);
scanf("%d%s%f",&p1->num,p1->name,&p1->score);
}
p2->next=NULL;
return head;
}
相似回答