title: How to read input of unknown length using fgets
body: <p>How am I supposed to read long input using <code>fgets()</code>, I don't quite get it.</p>
  
  <p>I wrote this</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  int main()
  {
      char buffer[10];
      char *input;
      while (fgets(buffer,10,stdin)){
          input = malloc(strlen(buffer)*sizeof(char));
          strcpy(input,buffer);
      }
      printf("%s [%d]",input, (int)strlen(input));
      free(input);
      return 0;
  }
  </code></pre>