c - Why am I able to get rid of seg. fault if I put printf()? -


my program has list handling functions, worked fine until added reverselinkedlist function. observed there seg. fault error, later on figured out adding printf() "solve" error, not sure why.

here snippet of code:

node *list_b; void functiona();  int main ( ) { ..      functiona();    printf("o.o\n");// <=== if add line, seg. fault gone. without it, got error    printsummary(); //this printing out whatever in list_b } void functiona() {    list_b = reverselinkedlist(list_b); }  node* reverselinkedlist(node *head) //this implemented in other head file. {     node *current = null;     node *temp;      while(head != null)     {         temp = head;         head = head->next;         temp->next = current;         current = temp;     }      return current; } 

calling printf changes values on stack. if functions after printf not initialize local variables properly, results in different behaviour including printf() or not.

you seem comparing stock_name before set (with malloc()). global variable?


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -