title: Simple Linked lists implementation in c
body: <p>I am trying to print my list more than 3 times.. </p>
  
  <p>It should be something like </p>
  
  <pre><code>A: 5  B: 2 C: 3
  A: 6  B: 4 C: 1
  A: 7  B: 3 C: 15
  A: 5  B: 2 C: 3
  A: 6  B: 4 C: 1
  </code></pre>
  
  <p>but after the 3rd time, it crashes..</p>
  
  <p>Please have a look at my code and show me how to fix it..</p>
  
  <p>PS: Moreover, can I edit the values of the list in the second/third run?? </p>
  
  <p>Thanks in advance,,</p>
  
  <pre><code>   #include &lt;stdio.h&gt;
      #include &lt;stdlib.h&gt;
      #include &lt;unistd.h&gt;
  
      struct list {
              int a,b,c;
              struct list *next;
      };
  
      struct list *init_list ( int a, int b, int c );
      void list_print( struct list *list );
  
      struct list *init_list ( int a, int b, int c ){
              struct list *list;
              list = malloc(sizeof(struct list));
              if (list == NULL) {
                      printf("Error: Memory allocation failure.\nTerminating.\n");
                      exit(1);
              }
  
              list-&gt;a = a;
              list-&gt;b = b;
              list-&gt;c = c;
              list-&gt;next = NULL;
              return (list);
      }
  
      void list_print(struct list *list) {
              int j = 0;
              struct list *list2;
              do {
                              list2 = list;
                              struct list *tmp; 
                              tmp = list;
  
                              printf("A: %d  B: %d C: %d\n" ,tmp-&gt;a, tmp-&gt;b, tmp-&gt;c);
                              list = list-&gt;next;
  
                              j++;
              } while (j &lt; 4);
      }
  
  
      int main (int argc, const char * argv[])
      {
          struct list *linked_list_1, *linked_list_2;
          linked_list_1 = init_list(5, 2, 3);
          linked_list_1-&gt;next = init_list(6, 4, 1); linked_list_2 = linked_list_1-&gt;next;
          linked_list_2-&gt;next = init_list(7, 3, 15); 
  
          list_print(linked_list_1);
  
          return 0;
      }
  </code></pre>