title: Little trouble with fgets and error handling
body: <p>i have recently started to learn C and have encountered a little problem with a code snipped.</p>
  
  <p>I want want wo read a character string, 20 chars long, over the stdin, so I have chosen fgets. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(int argc, char *argv[])
  {
  unsigned int length = 20;
  char input_buffer[length];
  fgets(input_buffer, length, stdin);
  if(input_buffer == NULL)
      printf("Error, input too long");
  else
      printf("%s", input_buffer);
  return 0;
  }
  </code></pre>
  
  <p>It compiles without any error, if I enter a sentence shorter than 20 characters, everything is fine. But when I try to test the error handling, it fails.</p>
  
  <p>The output is:</p>
  
  <pre><code>peter@antartica ~/test % ./test    
  Hello world, this is a very long test
  Hello world, this i%      
  </code></pre>
  
  <p>Am I doing anything wrong? I thought fgets returns a NULL pointer if it fails(which should be the case here)?</p>
  
  <p>Thank you for any help.</p>