title: Array entries being overwriten in C
body: <p>I want to convert an integer array to a string array. For example, if <code>arr[] = {1, 2, 3, 4, 5}</code>, I want to end up with <code>arr2[] = {"1", "2", "3", "4", "5"}</code>. This function works fine until it exits the <code>for</code> loop where all the array entries are being overwritten with the value of the last entry. Any idea as to why this might be happening?</p>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  #define SIZE 5
  int main(){
      int nums[] = {1, 2, 3, 4, 5};
      char **strings = (char **)malloc(SIZE * sizeof(char*));
  
      for(int i = 0; i &lt; SIZE; i++){
          char temp[20];
          sprintf(temp, "%d", nums[i]);
          strings[i] = temp;
          //prints correct values here
          printf("%s\n", strings[i]);
      }
  
      for(int i = 0; i &lt; SIZE; i++){
          //prints wrong values here
          printf("%s\n", strings[i]);
      }
  
      free(strings);
      return 0;
  }
  </code></pre>