title: assigning values in loop to array of character pointers
body: <p>I can't assign values to a char array in loop, doing it contains same value in every array value</p>
  
  <p>for example this works</p>
  
  <pre><code>char* foo[3];
  
  foo[0] = "mango"; foo[1] = "kiwi"; foo[2] = "banana";
  
  int i=0; for(i=0;i&lt;3;i++) 
  {
     printf("%s\n",foo[i]); 
  }
  </code></pre>
  
  <p>but this doesn't and I don't understand why.</p>
  
  <pre><code>char* foo[3]; int i=0;
  
  for(i=0;i&lt;3;i++) {
    char temp[5];
    sprintf(temp,"VAL:%d",i);
    foo[i] = temp; 
  }
  
  for(i=0;i&lt;3;i++) 
  {
    printf("%s\n",foo[i]); 
  }
  </code></pre>
  
  <p>please help and thanks in advance </p>