title: Linked list printing & adding elements
body: <p>So the idea is I have a Doubly linked list defined as a struct</p>
  
  <pre><code>struct Node
  {
      struct Node *next;
      struct Node *prev;
      char value[5];
  };
  
  struct DoubleLinkedList
  {
     int size;
     struct Node *head;
     struct Node *tail;
  };
  </code></pre>
  
  <p>and I'm inserting into the list using the InsertionSort function. I pass the pointer to my Doubly Linked list as a parameter to that and it gets modified with the addition of a new 4 character string node to the list(lexicographically sorted Linked list). I then print the linked list with the addition of each string node.</p>
  
  <p>The printing is proving to be problematic. Right now, with the code below, the output is always something like (assume the strings being inserted at every step are aaaa,bbbb,cccc...)</p>
  
  <p>aaaa</p>
  
  <p>bbbb -> bbbb</p>
  
  <p>cccc -> cccc -> cccc</p>
  
  <p>For some reason the linked list structure is changing each and every node to the value of the new string to be inserted; I have no idea why! And also, if I try shifting the print block to the main function, it prints out gibberish.</p>
  
  <pre><code>int main()
  {
      struct DoubleLinkedList strings;
      while (1)
  {
      sleep(1);
      char s[5];
      GenerateRandomString(s,4);
      InsertionSort(&amp;strings, s);
  }
      return 0;
  }
  
  void InsertionSort(struct DoubleLinkedList *sorted, char *randomstring)
  {
  struct Node new;
  strcpy(new.value,randomstring);
  printf("Newvalue %s\n", new.value);
  if ((*sorted).size == 0)
  {
      new.next = NULL;
      new.prev = NULL;
      (*sorted).head = &amp;(new);
      (*sorted).tail = &amp;(new);
  }
  else
  {
      printf("TEST %s\n", (*(*sorted).head).value);
      struct Node *current;
      current = (*sorted).head;
      printf("CURRENT %s\n", (*current).value);
      while (strcmp(randomstring,(*current).value) &gt; 0)
      {
          current = (*current).next;
          if (current = NULL)
          {
              break;
          }
      }
      new.next = current;
      if (current != NULL)
      {
          new.prev = (*current).prev;
          if ((*current).prev != NULL)
          {
              (*(*current).prev).next = &amp;(new);
          }
          else
          {
              (*sorted).head = &amp;(new);
          }
          (*current).prev = &amp;(new);
      }
      else
      {
          new.prev = (*sorted).tail;
          (*((*sorted).tail)).next = &amp;(new);
          (*sorted).tail = &amp;(new);
      }
  }
  (*sorted).size++;
  struct Node *printing;
  printing = (*sorted).head;
  int i;
  for (i = 0; i &lt; (*sorted).size - 1; i++)
  {
      printf("%s -&gt; ", (*printing).value);
      printing = (*printing).next;
  }
  printf("%s\n",(*printing).value);
  }
  </code></pre>