title: Reading stream char by char
body: <p>I'm using this function to read, char by char, a text file or a stdin input</p>
  
  <pre><code>void readLine(FILE *stream, char **string) {
      char c;
      int counter = 0;
  
      do {
          c = fgetc(stream);
          string[0] = (char *) realloc (string[0], (counter+1) * sizeof(char));
          string[0][counter++] = c;
      } while(c != ENTER &amp;&amp; !feof(stream));
  
      string[counter-1] = '\0';
  }
  </code></pre>
  
  <p>But when I call it, my program crashed and I really don't know why, because I don't forget the 0-terminator and I'm convinced that I stored correctly the char sequence. I've verified the string length, but it appears alright.</p>