title: Linked List Program is crashing again and again
body: <p>I have made a sorted linked list program. I don't know why, but it is crashing again and again. Tried to fix it but, didn't work. The problem seems to be in a print_list function, but don't know what's the problem.
  here's my code.</p>
  
  <pre><code>    #include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;conio.h&gt;
  
  struct node{
      struct node *next;
      int val;
  };
  
  struct LLADT{
  
      struct node *head;
  };
  
  void init(struct LLADT *LL){
      LL-&gt; head = 0;
  
  }
  
  // Printing a linked list
  void print_list(struct LLADT *LL){
      struct node *temp;
      temp = LL-&gt; head;
      while(temp -&gt;next!=NULL){  // changed temp!=NULL to temp-&gt;next!=NULL
          printf("%d\n", temp-&gt;val);
          temp = temp -&gt; next;
      }
  }
  
  //inserting sorted elements
  void sortInsert(struct LLADT *LL, int num){
  
      struct node *newNode;
      newNode-&gt;val = num;
      newNode-&gt;next = 0;
      newNode =(struct node*)malloc(sizeof(struct node));
  
  
      // Case -1: List is empty
  
      if(LL-&gt;head == 0){
          LL-&gt;head = newNode;
  
      }
      else{
  
          struct node *curr;
          curr = LL-&gt;head;
          struct node *prev;
          prev = NULL;
  
      // Traversing list to find the insert location
          while(curr != 0){
              if(curr-&gt;val &gt;= newNode-&gt;val){
                  break;
              }
  
              else{
  
                  prev = curr;
                  curr = curr -&gt; next;
              }
  
          // Case-2:
              if(curr == LL-&gt;head){
                  newNode-&gt;next = LL-&gt;head;
                  LL-&gt;head = newNode;
  
              }
              // case-3
              else{
  
                  newNode-&gt;next = curr;
                  prev-&gt;next = newNode;
              }
  
          }
  
      }
  }
  
  int main(){
  struct LLADT LL;
      sortInsert(&amp;LL,17);
      sortInsert(&amp;LL,3);
      sortInsert(&amp;LL,5);
      sortInsert(&amp;LL,2);
      sortInsert(&amp;LL,1);
      sortInsert(&amp;LL,20);
  
      //print_list(&amp;LL);
  
  getch();
  return 0;
  
  }
  </code></pre>
  
  <p>using codeblocks.</p>