# Thread: What's wrong with this program?

1. ## What's wrong with this program?

The link of the program is: <<<snipped>>> I use gdb to debug the program. It said that: Program received signal SIGSEGV, Segmentation fault.
0x080491c7 in simplify_polynomial (n=0x804c148) at test7.c:476
I don't know what is the problem. Could you help me? Thank you.

EDIT... there's no program code at that link... The Mods should close this thread.

3. ## The code is in the following. Thank you.

[code]

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <math.h>

typedef struct node /*a node denotes a P_{i,k}^{l}*/
{

int l,i,k;

} node;

typedef struct monomial_node /* a monomial denotes a monomial P_{i,k}^{l} \cdots P_{i',k'}^{l'} */

{
node y;
int coeff; /* coeff is the coefficent of the monomial */
struct monomial_node *next;
} monomial_node, *monomial;

typedef struct polynomial_node /* a polynomial denotes a sum of some monomials */

{

monomial m;

struct polynomial_node *next;

} polynomial_node, *polynomial;

monomial insert(node a, monomial b) /* insert a factor a to a monomial b such that the first subscripts i's in the new monomial is in increasing order */

{

monomial p;

monomial_node *s;

monomial_node *p1;

p=b;

if(p1==NULL)
{

s=malloc(sizeof(monomial_node));
s->y=a;
p->coeff=1;
}
else
{
while((p1->y).i >= a.i) /* find the position */
{

if(p1->next==NULL)
{

break;

}
p1=p1->next;

}
}

s=malloc(sizeof(monomial_node)); /* create new node */

s->y=a;

s->next=p1->next; /* insert the node a */

p1->next=s;

p->coeff=b->coeff;
return p;

}

monomial create_monomial(int number) /* create a monomial */

{

monomial m;

monomial_node *p, *s;

int i;

m=(monomial)malloc(sizeof(monomial_node));

{
printf("No memory.\n");
return NULL;

}

p=malloc(sizeof(monomial_node));

p->next=NULL;

printf("Please input the parameters of the heighest weight monomial(for example, 2, 2, 3 denotes the monomial Y^{2}_{2,3}). The first subscripts i of Y's should be in increase order.");

scanf("%d", &((p->y).l));
scanf("%d", &((p->y).i));
scanf("%d", &((p->y).k));

if(number > 1)
{
for(i=0;i<number-1;i++)

{

s=(monomial)malloc(sizeof(monomial_node));

scanf("%d", &((s->y).l));
scanf("%d", &((s->y).i));
scanf("%d", &((s->y).k));

m=insert(s->y,m);

}

}

m->coeff=1;

return m;

}

polynomial create_polynomial(monomial n) /* create a polynomial with only one monomial n */

{

polynomial m;
polynomial_node *p;

m=(polynomial)malloc(sizeof(polynomial_node));
p=(polynomial)malloc(sizeof(polynomial_node));

p->m=n;
p->next=NULL;

return m;

}

void print_monomial(monomial m)

{

monomial p;

if(p==NULL)

{

printf("No element. \n");

}

if(m->coeff == -1)
{
printf("-");
}
else if(m->coeff != 1)
{
printf("%d", m->coeff);
}

while(p!=NULL)

{

printf("Y^{%d}_{%d,%d}",(p->y).l,(p->y).i,(p->y).k);

p=p->next;

}

}

> I don't know what is the problem. Could you help me? Thank you.

What are these for?
Code:
```typedef struct monomial_node /* a monomial denotes a monomial P_{i,k}^{l} \cdots P_{i',k'}^{l'} */
{
node y;
int coeff;         /* coeff is the coefficent of the monomial */
struct monomial_node *next;
} monomial_node, *monomial;

typedef struct polynomial_node /* a polynomial denotes a sum of some monomials */
{
monomial m;
struct polynomial_node *next;