title: Doubling the size of a double pointer array?
body: <p>The goal is to read in 105 words in from a file and assign them to an array. The array is initialized to </p>
  
  <pre><code>char **array = (char**)malloc(*capacity * sizeof(char*)); 
  </code></pre>
  
  <p>where capacity is set to 50. </p>
  
  <p>I'm trying to make it so this function is called when 50 words have been read in and the 51st is being ready to. 
  The initial allocation for the array should be space for 50 pointers. If the array ever gets full (i.e., wordCount equals current capacity), and there's a word to insert, I will double the capacity of the array (i.e., malloc a new array of twice the current size, copy the strings over into the front half of the newly allocated array, and free the space used by the old array. I am not allowed to use realloc. I would just like help fixing the way to do this using my method. Please do not suggest alternate methods.</p>
  
  <p>So I keep getting a segmentation fault and I don't understand why. Any advice? </p>
  
  <pre><code>int doubleArraySize(char ***array, int count, int *capacity){ 
      char **temp = (char**)malloc(*capacity * sizeof(char*)); 
      if (temp = NULL){ 
          return -1; 
      } 
  
      int i = 0; 
      while(i&lt;count){ 
          temp[i] = *array[i]; 
          i++; 
      } 
  
      i = 0; 
      while(i&lt;count){ 
          free(*array[i]); 
          i++; 
      } 
  
      free(*array); 
      *array = temp; 
      return 0; 
  }
  </code></pre>
  
  <p>And yes I am not allowed to use realloc. I was specifically told to create a new array of double the size and copy the elements to the first half then free the old one. Also in a debugger i am using, it says the problem lies in the line </p>
  
  <pre><code>temp[i] = *array[i];
  </code></pre>
  
  <p>but i have no idea why. Thank you in advanced!</p>