title: How to read from stdin with fgets()?
body: <p>I've written the following code to read a line from a terminal window, the problem is the code gets stuck in an infinite loop. The line/sentence  is of undefined length, therefore I plan to read it in parts into the buffer, then concatenate it to another string which can be extended via <code>realloc</code> accordingly. Please can somebody spot my mistake or suggest a better way of achieving this?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  #define BUFFERSIZE 10
  
  int main (int argc, char *argv[])
  {
      char buffer[BUFFERSIZE];
      printf("Enter a message: \n");
      while(fgets(buffer, BUFFERSIZE , stdin) != NULL)
      {
          printf("%s\n", buffer);
      }
      return 0;
  }
  </code></pre>