title: Typing a unexpected input causes loop to fail (C)
body: <p>While testing a program(in C) to prevent any bugs, I clicked \ by accident when the program asked for an integer. The while loop then starts failing. An example:</p>
  
  <pre><code>int a;
  while(1){
      scanf("%d",&amp;a);printf("%d\n",a);
      a--;
      if(a==0){break;}
  }
  </code></pre>
  
  <p>Whenever I type a number, it is supposed to print the same number. But when I type a character, it will print out all numbers below the previous input and then starts printing all numbers below it till 1. 
  Can anyone give a clue on fixing this problem? Thanks a lot.</p>
  
  <p>Edit: This program is just a sample of the bug, the actual program is much larger than this. </p>