title: Reading in a string of unknown length from the console
body: <p>If I want to read in a string of arbitrary length from the command line, what's the best way of going about it?</p>
  
  <p>At the moment I'm doing this:</p>
  
  <pre><code>char name_buffer [ 80 ];
  int chars_read = 0;
  while ( ( chars_read &lt; 80 ) &amp;&amp; ( !feof( stdin ) ) ) {
     name_buffer [ chars_read ] = fgetc ( stdin );
     chars_read++;
  }
  </code></pre>
  
  <p>But what can I do if the string is longer than 80 characters? Obviously I could just initialise the array to a bigger number but I'm sure there must be a better way to give the array more space using malloc or something? </p>
  
  <p>Any hints would be great.</p>