Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is in this declaration:</p> <pre><code>struct list **pre, **aft, **head; </code></pre> <p>So, they are pointers to a pointer to a list, and then, you do things like this:</p> <pre><code>*pre = NULL; </code></pre> <p>The problem is that <code>pre</code> has not been initialized, so it holds garbage at this point. You are basically setting a random address in memory to NULL. You have two options: allocate space for them (with malloc and free afterwards), or change them to be like this:</p> <pre><code>struct list *pre, *aft, *head; </code></pre> <p>That way, they can be assigned safely. Your function would be modified like this:</p> <pre><code>void reverse(struct list **temp) { struct list *pre, *aft, *head; pre = NULL; head = *temp; if(head == NULL ) { return; } else { while(head!= NULL) { aft =head-&gt;next; head-&gt;next = pre; pre = head; head = aft; printf("%d\t",pre-&gt;node); } *temp = pre; } } </code></pre> <p>Doing that, I get the following output:</p> <pre><code>10 20 30 40 50 60 70 hello 70 60 50 40 30 20 10 </code></pre> <p>EDIT:</p> <p>I've also noticed that you are changing the value of <code>head</code> inside the functions <code>insert</code> and <code>print</code>. I recommend using a temporal variable instead to iterate the list. That also frees you from that trick you were using in <code>main</code> with <code>tmp</code>.</p> <p>Anyway, the complete code modified can be seen <a href="http://ideone.com/qNZgGi" rel="nofollow">here</a>. If yours is still giving you trouble, post an update or Ideone link with the modified code that still fails.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload