title: Using scanf to read strings into an array of strings
body: <p>I'm trying to make a simple program that keeps reading strings from the standard input using scanf and putting them into an array of strings (Right now I'm just testing it using 3 words, hence only 3 print statements at the end). I'm able to keep reading until there are no more strings, however I've encountered a bug where after the looping is done, all the strings in the array are the last string read in. I've tried putting a print statement within the loop to debug, and it is reading in the correct string. However when the looping is finished, all the strings in the array are the last string read in. Can anyone point out where I'm going wrong here? Thanks.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  
  
  int main(void) {
      int c = 0;
      char** w_arr = malloc(3*sizeof(char*));
      char* w = malloc(10*sizeof(char));
  
      while (scanf("%s", w) == 1) {
          w_arr[c] = w;
          //printf("%s", w_arr[c]); debug print statement
          c++;
      }
  
      printf("%s, %s, %s\n", w_arr[0], w_arr[1], w_arr[2]);
      return 0;
  }
  </code></pre>