title: Reading from a file and storing in array
body: <p>I've written the following program to read line by line from a file and store it in the words array. The output should be two random words from the array. But surprisingly the words array contains only the last word read repeatedly. Any help on what went wrong? </p>
  
  <pre><code>int main(){
   int i = 0;
   char line_buffer[BUFSIZ];
   char* words[20];
   FILE *fp = fopen("input.txt", "r");
    while (fgets(line_buffer, sizeof(line_buffer), fp)) {
    //printf("%s", line_buffer); 
    words[i] = line_buffer;
    i = i + 1;
   } 
   printf("%d", i);
   int j = rand()%8;
      int k = (j+1)%8;
   printf("%s %s", words[j], words[k]); 
   fclose(fp);
   return 0;
  }
  </code></pre>
  
  <p>input.txt </p>
  
  <pre><code>nematode knowledge
  empty bottle
  nevertheless
  claustrophobia
  metamorphosis
  acknowledgement
  impossibility
  never gave up
  </code></pre>