title: C fgets versus fgetc for reading line
body: <p>I need to read a line of text (terminated by a newline) without making assumptions about the length. So I now face to possibilities:</p>
  
  <ul>
  <li>Use <code>fgets</code> and check each time if the last character is a newline and continuously append to a buffer</li>
  <li>Read each character using <code>fgetc</code> and occasionally <code>realloc</code> the buffer</li>
  </ul>
  
  <p>Intuition tells me the <code>fgetc</code> variant might be slower, but then again I don't see how <code>fgets</code> can do it without examining every character (also my intuition isn't always that good). The lines are quite large so the performance is important.</p>
  
  <p>I would like to know the pros and cons of each approach. Thank you in advance.</p>