c - Linked list representation of a polynomial -


i have write program sum 2 polynomials. purpose, first of all, writing program take 2 polynomials , print them.

my program this:

#include <stdio.h> #include <stdlib.h> #include <string.h>  struct node {     int power;     int coef;     struct node *link; };    int input( struct node *phead); int display( struct node *phead);  int main() {     struct node *phead= malloc(sizeof(struct node)),*qhead = malloc(sizeof(struct node));     input(phead);     display(phead);      input(qhead);     display(qhead);      return 0; }  int input( struct node *phead) {     //phead      //qhead = malloc(sizeof(struct node));     int value;      printf("\n\t\tentry of polynomial:\n");      printf("enter coefficient: ");     scanf("%d",&phead->coef);     printf("enter power: ");     scanf("%d",&phead->power);     phead->link = null ;      printf("enter coefficient,( 0 break ): ");     scanf("%d", &value);      while ( value != 0 )     {         struct node *new_node = malloc(sizeof(struct node ));          new_node -> coef = value;          printf("enter power: ");         scanf("%d",&new_node->power);         new_node->link = phead;         phead = new_node;          //printf("%d",phead->power);         printf("enter coefficient,( 0 break ): ");         scanf("%d", &value);     }     return 0; }  int display( struct node *phead) {     struct node *temp = phead;     //printf("i in display.\n");      while ( temp != null )     {         //printf("i in while.\n");         printf("%d * x ^ %d + ",temp->coef,temp->power);         temp=temp->link;     }     //printf("%d * x ^ %d + ",temp->coef,temp->power);     //printf("0");      return 0; } 

i unable print polynomial.the issue temp variable. please me solve this.

the problem part of code:

new_node->link = phead; phead = new_node;  

solve follows:

phead->link = new_node; phead = new_node;  

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -