title: C infinite loop when char input instead of int
body: <p>I have a C program which is supposed to validate that the input from the user is an int between 1 and 8. It works if an integer is entered, but when characters are entered the validation loop repeats forever. Can you tell what I am doing wrong?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void)
  {
    int i;
    int input;
    domainEntry *myDomains = buildDomainDB();
  
    printf("You have the choice between the"
           " following top domains: 1-EDU, 2-COM"
           ", 3-ORG, 4-GOV, 5-MIL, 6-CN, 7-COM.CN, 8.CAN\n");
    printf("Which one do you want to pick?");
    scanf(" %d", &amp;input);
  
    if(input &lt; 1 || input &gt; 9)
    {
      do  
      {   
        printf("Invalid input. Please try again.");
        printf("You have the choice between the"
               " following top domains: 1-EDU, 2-COM"
               ", 3-ORG, 4-GOV, 5-MIL, 6-CN, 7-COM.CN, 8.CAN\n");
        printf("Which one do you want to pick?");
        scanf(" %d", &amp;input);
  
      }while((input &lt; 1) || (input &gt; 8));
    }
  }
  </code></pre>