title: Filling in a queue with C
body: <p>correction it works now thanks everyone.</p>
  
  <p>Okay so now I have updated my main file to<br>
  main.c</p>
  
  <pre><code>#include "queue.h"
  
  int main(){
      int i;
      int* dataPtr;
      int number;
      QUEUE* numbers;
      numbers = createQueue ();
  
      printf("Please enter the 10 numbers you want to know the sum and average of.\n");
  
      for (i = 0; i &lt; 10; i++){
          printf("Number %d: ", i+1);
          scanf("%d", &amp;number);
          *dataPtr = number;
          enqueue(numbers, dataPtr);
      }
  
  
  
    system("Pause");
    return 0;
  
  }
  </code></pre>
  
  <p>But my program crashes when it is ran<br>
  Does anyone know why this is happening?</p>
  
  <p><strong>Original Post</strong>  </p>
  
  <p>I am having trouble figuring out how to fill a queue with user input in C. Can anyone point me in the right direction.</p>
  
  <p>queue.h:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdbool.h&gt;
  
  //Queue ADT Type Definitions
          typedef struct node{
                  void* dataPtr;
                  struct node* next;
          } QUEUE_NODE;
  
          typedef struct{
                  QUEUE_NODE* front;
                  QUEUE_NODE* rear;
                  int count;
          } QUEUE;
  
  //Prototype Declarations      
          QUEUE* createQueue (void);
          QUEUE* destroyQueue (QUEUE* queue);
  
          bool dequeue        (QUEUE* queue, void** itemPtr);
          bool enqueue        (QUEUE* queue, void*  itemPtr);
          bool queueFront     (QUEUE* queue, void** itemPtr);
          bool queueRear      (QUEUE* queue, void** itemPtr);
          int  queueCount     (QUEUE* queue);
  
          bool emptyQueue     (QUEUE* queue);
          bool fullQueue      (QUEUE* queue);
  //End of Queue ADT definitions
  </code></pre>
  
  <p>Queue.c</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include "queue.h"
  QUEUE* createQueue (void){
         QUEUE* queue;
  
         queue = (QUEUE*) malloc (sizeof (queue));
         if (queue){
            queue-&gt;front  = NULL;
            queue-&gt;rear   = NULL;
            queue-&gt;count  = 0;
         }
         return queue;
  }
  
  bool enqueue (QUEUE* queue, void* itemPtr){
       QUEUE_NODE* newPtr;
  
       if(!(newPtr = (QUEUE_NODE*)malloc(sizeof(QUEUE_NODE))))
                   return false;
  
       newPtr-&gt;dataPtr    = itemPtr;
       newPtr-&gt;next       = NULL;
  
       if (queue-&gt;count == 0)
           queue-&gt;front = newPtr;
       else
           queue-&gt;rear-&gt;next = newPtr;
  
       (queue-&gt;count)++;
       queue-&gt;rear = newPtr;
       return true;
  }
  
  bool dequeue (QUEUE* queue, void** itemPtr){
       QUEUE_NODE* deleteLoc;
  
       if (!queue-&gt;count)
          return false;
  
       *itemPtr  = queue-&gt;front-&gt;dataPtr;
       deleteLoc = queue-&gt;front;
       if(queue-&gt;count == 1)
           queue-&gt;rear  = queue-&gt;front = NULL;
       else
           queue-&gt;front = queue-&gt;front-&gt;next;
       (queue-&gt;count)--;
       free (deleteLoc);
  
       return true;
  }
  
  bool queueFront (QUEUE* queue, void** itemPtr){
       if (!queue-&gt;count)
          return false;
       else{
            *itemPtr = queue-&gt;front-&gt;dataPtr;
            return true;
       }
  }
  
  bool queueRear (QUEUE* queue, void** itemPtr){
       if (!queue-&gt;count)
          return true;
       else{
            *itemPtr = queue-&gt;rear-&gt;dataPtr;
            return false;
       }
  }
  
  bool emptyQueue (QUEUE* queue){
       return (queue-&gt;count == 0);
  }
  
  bool fullQueue(QUEUE* queue){
       QUEUE_NODE* temp;
  
       temp = (QUEUE_NODE*)malloc(sizeof(*(queue-&gt;rear)));
       if (temp){
                 free (temp);
                 return true;
                 }
       return false;
  }
  
  int queueCount(QUEUE* queue){
      return queue-&gt;count;
  }
  
  QUEUE * destroyQueue (QUEUE* queue){
        QUEUE_NODE* deletePtr;
  
        if (queue){
                   while (queue-&gt;front != NULL){
                         free (queue-&gt;front-&gt;dataPtr);
                         deletePtr = queue-&gt;front;
                         queue-&gt;front = queue-&gt;front-&gt;next;
                         free(deletePtr);
                   }
                   free (queue);
        }
        return NULL;
  }
  
  main.c
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include "queue.h"
  
  int main(){
      int number;
      int *dataPtr;
      QUEUE* numbers;
      numbers = createQueue ();
  
      printf("Please enter the 10 numbers you want to know the sum and average of.\n");
  
      for (int i = 0, i &lt; 10; i++){
          if (!(dataPtr = (int*) malloc (sizeof (int))))
             printf("Overflow trying to fill queues.\n"), exit(100);
  
  
  
  
    system("Pause");
    return 0;
  
  }
  </code></pre>