title: How to initialize and allocate memory to a data-structure and pass to another function
body: <p>First, I have a data-structure <code>struct cashier</code>  that I defined and needed to be initialized. It is put in <code>queue.c</code> file for <code>queue.h</code> file to use. <a href="https://i.stack.imgur.com/BnMli.jpg" rel="nofollow noreferrer">1</a></p>
  
  <pre><code>/* queue.c */
      struct cashier {
          int numberOfCustomersServed; /* This should be initialized to 0 */
          int totalCustomerWaitingTime; /* This should be initialized to 0 */
          float totalAmountReceived; /* This should be initialized to 0 */
         queueADT customerQ; /* This should be initialized to an empty queue */
      };
  </code></pre>
  
  <p>Then, I have a <code>queue.h</code> file for the main program <code>supermarket.c</code> file. And I defined the type <code>cashierT</code> and multiple other queue functions.( <code>queueADT getEmptyQueue(void);</code> is to malloc the data-structure "queue" that I created and give memory space to it.) <a href="https://i.stack.imgur.com/hPxzS.jpg" rel="nofollow noreferrer">2</a></p>
  
  <pre><code>  /* queue.h*/
       typedef struct cashier cashierT;
  </code></pre>
  
  <p>In the main program <code>supermarket.c</code> , I initialize the cashier structure.</p>
  
  <pre><code>/* supermarket.c*/
  cashierT initCashier(void){
      cashierT x;
      x.numberOfCustomersServed=0;
      x.totalCustomerWaitingTime=0;
      x.totalAmountReceived=0.0;
      x.customerQ=getEmptyQueue();
  
      return x;
    }; 
  </code></pre>
  
  <p>But then, I get some errors: <a href="https://i.stack.imgur.com/QoXUH.jpg" rel="nofollow noreferrer">3</a></p>
  
  <pre><code>/cygdrive/c/Users/Heta/Desktop/CLionHWQ2/supermarket.c:12:10: error: return type is an incomplete type
   cashierT initCashier(void){
            ^~~~~~~~~~~
  /cygdrive/c/Users/Heta/Desktop/CLionHWQ2/supermarket.c: In function 'initCashier':
  /cygdrive/c/Users/Heta/Desktop/CLionHWQ2/supermarket.c:13:14: error: storage size of 'x' isn't known
       cashierT x;
                ^
  </code></pre>
  
  <p>But if I copy and paste the whole <code>struct cashier</code> in <code>supermarket.c</code> the error disappeared. <a href="https://i.stack.imgur.com/LkJpY.jpg" rel="nofollow noreferrer">Ref 3</a> 
   <a href="https://i.stack.imgur.com/L5ikB.jpg" rel="nofollow noreferrer">Ref 1</a>.  Why is there such a problem and how can I fix it if I want to keep the <code>struct cashier</code> and initialization in <code>queue.c</code> ?</p>