C语言程序运行错误。
下面C语言程序的 p=n->head->next; 用gdb调试的时候报错,Program received signal SIGSEGV, Segmentation fault.0x0804919b in simplify_polynomial (n=0x804c188) at test7.c:475
475 p=n->head->next; 找了很久没发现错误在哪里。 请问错误在哪里? 完整程序在:http://hi.baidu.com/lijr03/blog/item/dd824f7e2cb804f42e73b3a1.html。谢谢
polynomial simplify_polynomial(polynomial n)
{
polynomial p;
polynomial_node *p1, *s;
p=n;
p=n->head->next;
while(p!=NULL)
{
p->m=simplify_monomial(p->m);
p=p->next;
}
p1=p->head->next;
p=p->head->next;
s=p;
while(p!=NULL) /* merge the terms with the same monomials */
{
while(p1!=NULL)
{
if(compare_monomials(p->m, p1->m)==1)
{
p->m->coeff=p1->m->coeff + p->m->coeff;
p=delete_monomial(p, p1->m);
p1=s;
p=s->next;
}
p1=p1->next;
}
p=p->next;
s=p; /* s records the position of p */
p1=p;
}
p1=p->head->next;
while(p1 != NULL)
{
if(p1->m->coeff==0)
{
p=delete_monomial(p, p1->m);
}
p1=p1->next;
}
return p;
}