title: Linux non deterministic behaviour taking input
body: <p>I have written this function:</p>
  
  <pre><code>char* input(char* buffer, FILE* fp)
  {
      char* result=fgets(buffer,LMAX,fp);
      if(result!=NULL)
      {
      const unsigned int length=strlen(buffer);
      if(buffer[length-1]=='\n')
          buffer[length-1]='\0';
      }
      return result;
  }
  </code></pre>
  
  <p>It just takes in input a line of text if fp is equal to stdin.<br>
  I have used it many times and it works.<br>
  I take the result of fgets just in the case fp is a FILE pointer, so I have to check that the result is not NULL in the case the stream is not good for input operations.<br>
  The problem is that if I use it this way:  </p>
  
  <pre><code>char buffer[LMAX];  // LMAX = 100, defined constant
  input(buffer,stdin);
  puts(buffer);
  </code></pre>
  
  <p>If the input is like "#dest :a", the puts prints "#dest", cutting the rest of the string.The big problem is that this function was working and one hour ago (it was identical) if I did take in input a string like "#dest :a" the puts was printing "#dest :a".And nothing has changed.Also if I try debugging and I write this:</p>
  
  <pre><code>char* input(char* buffer, FILE* fp)
  {
      char* result=fgets(buffer,LMAX,fp);
      puts(buffer);  //prints always "#dest :a"
      if(result!=NULL)
      {
      const unsigned int length=strlen(buffer);
      if(buffer[length-1]=='\n')
          buffer[length-1]='\0';
      }
      return result;
  }
  </code></pre>
  
  <p>The problem is that in the function it prints "#dest :a".<br>
  This function sometimes works and sometimes not, I'm K.O., I can't stand a non deterministic behaviour, what could be this problem (and probably a bug) dued to?</p>