title: Queue struct losing element values after being called once
body: <p>I am writing a queue struct in C that takes strings (char pointers) as the element. The problem I'm having is that after printing the element value once, it comes out null afterwards.</p>
  
  <p>With the code below, I am expecting this output:</p>
  
  <pre><code>1 Hello
  1 Hello
  2 World
  Hello World
  1
  </code></pre>
  
  <p>But I am getting this output:</p>
  
  <pre><code>1 Hello
  1 (null)
  2 World
  (null) (null)
  1
  </code></pre>
  
  <p>Can someone enlighten me on what I'm doing wrong?</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  
  struct Node {
      struct Node *next;
      char* element; 
  };
  struct Queue {
      int size;
      struct Node *head;
      struct Node *tail;
  
  };
  
  void Enqueue(struct Queue *q, char* str) {
      struct Node newNode = {0,str};
      if(q-&gt;size == 0) {
          q-&gt;head = &amp;newNode;
      }
      else {
          q-&gt;tail-&gt;next = &amp;newNode;   
      }
      q-&gt;tail = &amp;newNode;
      q-&gt;size = q-&gt;size + 1;
  }
  char* Dequeue(struct Queue *q) {
      if(q-&gt;size &lt; 0) {   
          return -1;
      }
      char* tbr = q-&gt;head-&gt;element;
      struct Node* oldNode = q-&gt;head;
      q-&gt;head = oldNode-&gt;next;
      q-&gt;size = q-&gt;size - 1;
      if(q-&gt;size == 0) {
          q-&gt;tail = NULL;
      }
      return tbr;
  }
  int IsEmpty(struct Queue *q) {
      return q-&gt;size == 0;
  }
  char* Peek(struct Queue *q) {
      return q-&gt;head-&gt;element;
  }
  int main() {
      struct Queue q = {0};
      Enqueue(&amp;q,"Hello");
      printf("%d %s\n",q.size,q.head-&gt;element);
      printf("%d %s\n",q.size,q.head-&gt;element);
      Enqueue(&amp;q,"World");
      printf("%d %s\n",q.size,q.head-&gt;next-&gt;element);
      printf("%s %s\n",Dequeue(&amp;q),Dequeue(&amp;q));
      printf("%d\n",IsEmpty(&amp;q));
      printf("%s %s\n","Hello","World");
      Dequeue(&amp;q);
      return 0;
  }
  </code></pre>