title: why do I get "Segmentation fault" when assigning values to array of pointers
body: <p>I have this peace of C Programming code to take multiple literal strings from the user and store each address to each pointer and print out the value</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int main(int argc, char *argv[])
  {
      char *ptr[3];
      int i = 0;
  
      for (; i &lt; 3; i++) {
          printf(&quot;ptr_%d:  &quot;, i + 1);
          fgets(ptr[i], 15, stdin);
          ptr[i][strlen(ptr[i]) - 1] = 0;
          puts(ptr[i]);
      }
  
      return 0;
  }
  </code></pre>
  <p>However, only the first one is printed. Here is the output</p>
  <pre><code>ptr_1:  first line
  first line
  Segmentation fault
  
  [Program finished]
  </code></pre>
  <p>I want the same result that is produced Here</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int main(int argc, char *argv[])
  {
      char *ptr[] = {
          &quot;first line&quot;, 
          &quot;second line&quot;, 
          &quot;third line&quot;
      };
  
      puts(ptr[0]);
      puts(ptr[1]);
      puts(ptr[2]);
          
      return 0;
  }
  </code></pre>
  <p>output</p>
  <pre><code>first line
  second line
  third line
  
  [Program finished]
  </code></pre>
  <p>Thanks in advance</p>