-写了个单链表,编译时没问题。但是运行时有错误。。
-建立链表那段都通不过。高手帮帮忙。万分感谢^_^。
#include <stdio.h>
#include <stdlib.h>
struct student {
int num;
float score;
struct student * next;
};
int main()
{
struct student *head=NULL;
struct student *p1,*p2;
int n=0;
p1=p2=(struct student*)malloc(sizeof(struct student));
scanf("%d,%f",&p1->num,&p1->score);
while(p1->num)
{
n++;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(sizeof(struct student));
scanf("%d,%f",&p1->num,&p1->score);
}
p2->next=NULL;
return 0;
}
[此贴子已经被作者于2007-2-4 22:22:12编辑过]