title: Set initial values to fields of a struct in c ?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/330793/how-to-initialize-a-struct-in-ansi-c">How to initialize a struct in ANSI C</a>  </p>
  </blockquote>
  
  
  
  <p>I have a global variables in my code <strong>with initial values</strong> , which are : </p>
  
  <pre><code>int init = 0;
  int flag = FALSE;
  sem_t *mutex;
  char * ptr1 = NULL;
  char * ptr2 = NULL;
  int status1 = -10;
  int status2 = -10;
  int semaphoreFlag = FALSE;
  </code></pre>
  
  <p>Instead , I decided to add a struct :</p>
  
  <pre><code>struct PipeShm
  {
      int init;
      int flag;
      sem_t *mutex;
      char * ptr1;
      char * ptr2;
      int status1;
      int status2;
      int semaphoreFlag;
  };
  </code></pre>
  
  <p>However ,I can't set initial values to the struct's fields , like I did when 
  the variables are global variables . </p>
  
  <p>I guess that the usual way would be to have a <code>void init()</code> method 
  that would set the values of the struct to the requested values ... but I'm looking for something else ... Any way around this ?</p>
  
  <p>Thanks </p>