title: fgetc(): Reading and storing a string of unknown length
body: <p>What I need to do for an assignment is:</p>
  
  <ul>
  <li>open a file (using fopen())</li>
  <li>read the name of a student (using fgetc())</li>
  <li>store that name in some part of a struct</li>
  </ul>
  
  <p>The problem I have is that I need to read an arbitrary long string into name, and I don't know how to store that string without wasting memory (or writing into non-allocated memory).</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>My first idea was to allocate a 1 byte (char) memory block, then call realloc() if more bytes are needed but this doesn't seem very efficient. Or maybe I could double the array if it is full and then at the end copy the chars into a new block of memory of the exact size. </p>