When I call the print_linklist function I am getting a segmentation fault. Here is the function definition:
//will display the node in a nice string
char * term_to_string(term_t * term){
int exp = term->exponent;
int coef = term->coefficient;
return ("%dx^%d", coef, exp);
}
**//will print the list using the nodde_to_string method
void print_linklist(node_t * curr){
printf("entering print to list!!!");
node_t * current = curr;
while(current != NULL){
printf("%s +", term_to_string(curr->term));
current = current->next_node;
}
}**
And here is the main method where it is being called:
/* This is your main file */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"common.h"
#include"buildlinklist.h"
#include"printandcombine.h"
int main() {
node_t * node_ptr = NULL;
node_t * new_node_ptr=NULL;
printf("NAME: SAMPLE OUTPUT\n");
/* Build linklist */
read_objects(&node_ptr);
/* Print the link list */
printf("Original: \n");
print_linklist(node_ptr);
/* Combine like terms in the link list and craeate a new link list */
new_node_ptr=combine_like_terms(node_ptr);
printf("\nCombined: : ");
/* Print new combine linklist */
print_linklist(new_node_ptr);
printf("\nNAME: SAMPLE OUTPUT\n");
free(node_ptr);
free(new_node_ptr);
return 0;
}
After the function is called I get "zsh: segmentation fault ./project1". I don't even get the "entering print to list!!!" to print from the print_linklist method.