title: Why does scanf get stuck in an infinite loop on invalid input?
body: <p>In line 5 I read an integer and <code>isint</code> is getting 1 if it reads an integer or 0 if it's not an integer. If <code>isint</code> is 0 I have a loop asking user to give an integer and I read until the user gives an integer. I try this code giving a character instead of an integer but I have an infinite loop. The program just doesn't wait to give a new input. What's wrong with my code?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void) {
  
    int arg1;
    //int arg2;
    int attacknum = 1;
    int isint = 1;
  
    //printf("Insert argument attacks and press 0 when you have done this.\n");
    printf("Attack %d\n", attacknum);
    attacknum++;
    printf("Give attacking argument:");
    isint = scanf("%d", &amp;arg1);  //line 5
  
    while(isint == 0){
      printf("You did not enter a number. Please enter an argument's number\n");
      isint = scanf("%d", &amp;arg1);
      printf("is int is %d\n", isint);
    }
    return 0;
  }
  </code></pre>