title: How to use fgets() and store every line of a file using an array of char pointers?
body: <p>I wrote the program below in order to read every line of the file and then store each line in a array of char pointers for later use (like sorting only the pointers not the real strings). <strong>But the problem is that it keeps storing the same line.</strong></p>
  
  <p>Lets say that the file is called <em>file.txt</em> and has two(2) lines with text.</p>
  
  <pre><code>  first sentence
    second sentence
  </code></pre>
  
  <p>The code I wrote is the following:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;strings.h&gt;
  #include &lt;unistd.h&gt;
  
  int main(){
      FILE *cf;
      cf = fopen("file.txt", "r");
      char line[101];
      char *lines[2];
      char *eof;
  
      int i=0;
      while((eof = fgets(line, 101, cf)) != NULL){
          lines[i] = eof;
          i++;
      }
  
      printf("%s\n", lines[0]);
      printf("%s\n", lines[1]);
  
      system("pause");
      return 0;
  }
  </code></pre>
  
  <p>The output I get is:</p>
  
  <pre><code>second sentence
  second sentence
  </code></pre>
  
  <p>But I want to get:</p>
  
  <pre><code>first sentence
  second sentence
  </code></pre>
  
  <p>What I am doing wrong here?</p>
  
  <p>-Thanks for your help :-)</p>