title: Realloc an array of Structs
body: <p>I am trying to dynamically reallocate memory for an array of structs (actually an array each of 2 structs but 1 included here for simplicity) that is being read from/to a file or inputted by the user.</p>
  
  <pre><code>typedef Struct
  {
      char surname[21];
      char firstname[21];
      char username[21];
  ...
  } User;
  </code></pre>
  
  <p>...in main():</p>
  
  <pre><code>int size = 0; /* stores no. of structs */
  User* user_array = (User *) calloc(1, sizeof(User));
  if(user_array == NULL)
  {
      printf("Cannot allocate initial memory for data\n");
      exit(1);
  }
  else
      size++;
  </code></pre>
  
  <p>I am then trying to use a function call to increase the array when needed:</p>
  
  <pre><code>int growArray(User user_array*, int size)
  {
      User *temp;
      size++;
      temp = (User *) realloc(user_array, (size * sizeof(User));
      if(temp == NULL)
      {
          printf("Cannot allocate more memory.\n");
          exit(1);
      }
      else
          user_array = temp;
      return size;
  }
  </code></pre>
  
  <p>Unfortunately the realloc never works. Both structs are only about 200 bytes per instance and setting the initial size to say 10 will work fine, so there must be something wrong with the way I am trying to use realloc.</p>
  
  <p>System is Win 7 64, on Core i5 with 4GB, running Quincy (a MinGW GUI).</p>