关于scanf和链表的问题
我用vc的编译器调试的,虽然编译没有错误,但第二个num输入后,编译器告知我调试错误,我翻阅书本,查不出为什么?程序如下:
#include<stdio.h>
#include<malloc.h>
#define NULL 0
#define len sizeof(struct student)
struct student
{
int num;
struct student *next;
};
struct student *main(void)//main可有其他函数代替,我只是测试而已
{
struct student *p,*pback,a,*head;
int i=1;
pback=p=(struct student *)malloc(len);
scanf("%d",&a.num);
p->num=a.num;
while(p->num!=0)
{
if(i==1)
head=pback;
else
pback->next=p;
pback=pback->next;
p=(struct student *)malloc(len);
scanf("%d",&a.num);
p->num=a.num;
i++;
}
pback->next=NULL;
return head;
}