title: Code to store a file's lines in a char double pointer is storing the same line in all elements
body: <p>I want to make a code that reads a file and stores each line of it into a string. On the other hand, I store these strings into another array, which makes a char double pointer. The code is printing the file rightly, but when I try to print a string (one of the lines) randomly it always outputs the last line of the file ("{").</p>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
      //I Open the file
      FILE* file_1 = fopen ("Caso2.ll", "r");
      char string[1000];
      //I create a double pointer to char of size 1000 (big enough to store any string)
      char ** string_2 = (char**) malloc(sizeof(char *)*1000);
      int i =0;
      //While fgets is different from NULL
      while (fgets(string, 1000, file_1)!= NULL)
      {
          //I define each element of string_2 as a char pointer (string)
          string_2[i] = (char *)malloc(sizeof(char)*1000);
          //and attribute string to string_2, thus storing the read line into it
          string_2[i] = string;
          //I print string_2
          printf("%s", string_2[i]);
          i++;
      }
      //Until now everything is okay. The code is printing the file okay.
      printf("\n\n\n\n\n\n\n");
      //Here is where the error is. When I try to print a random element of 
      //string_2, it always prints "{", the last line of the file
      fputs(*(string_2 + 5), stdout);
      system("pause");
      return 0;
  }
  </code></pre>