title: How to clear input buffer after fgets overflow?
body: <p>I'm facing a little problem with fgets when the input string exceeds its predefined limit.</p>
  
  <p>Taking the example below:</p>
  
  <pre><code>    for(index = 0; index &lt; max; index++)
      {printf(" Enter the %d string : ",index+1)
                  if(fgets(input,MAXLEN,stdin))
                  {
                      printf(" The string and size of the string is %s and %d \n",input,strlen(input) + 1);
                      removeNewLine(input);
                      if(strcmp(input,"end") != 0)
                     { //Do something with input
                     }
                  }
  </code></pre>
  
  <p>Now when I exceed the length MAXLEN and enter a string, I know that the input will append a '\0' at MAXLEN -1 and that would be it. The problem happens when I try to enter the 2nd string which is not asked for  i.e</p>
  
  <pre><code>Output :
  Enter the first string : Aaaaaaaaaaaaaaaaaaaa //Exceeds limit
  Enter the second string : Enter the third string : ....Waits input
  </code></pre>
  
  <p>So, I thought I should clear the buffer the standard way as in C. It waits until I enter </p>
  
  <pre><code>return
  </code></pre>
  
  <p>two times, The first time it being appended to the string and the next time,expecting more input with another return.
  1. Is there any method by which I can clear the buffer without entering the extra return?
  2. How do I implement error handling for the same? Because the fgets return value will be Non-null and strlen(input) gives me the accepted size of the string by fgets, what should  be done?</p>
  
  <p>Thanks a lot</p>