运行过程中出错自动中断,求解。
#include<stdio.h>#include<stdlib.h>
#define len sizeof(Member)
struct member
{int num;
struct member *next;
};
typedef struct member Member;
void insertup(Member *head, Member *newp)
{Member *pre,*suc;
pre=head;
suc=head->next;
while (suc!=NULL)
{if (suc->num >=newp->num)
break;
pre=suc;
suc=suc->next;
}
pre->next=newp;
newp->next=suc;
}
void main()
{
int n,i=0;
Member *head,*p,*q,*a;
head=p=q=(Member *)malloc(len);
printf("请输入要创建数据的个数:");
scanf("%d",&n);
printf("请按从小到大依次输入每个成员的号码\n");
while(i<n)
{
scanf("%d",&p->num);
q=(Member *)malloc(len);
p->next=q;
if(i==n-1)p->next=NULL;
p=q;
i++;
}
printf("请输入要插入的数据:");
scanf("%d",&a->num);
insertup(head,a);
printf("插入后的数据为:");
i=0;
p=head;
while(i<=n)
{
printf("%d",p->num);
p=p->next;
i++;
}
}