C scanf ignored when invalid input : <p>I wrote this code, and all it meant to do is input ints until a negative is entered:</p>

<pre><code>int result = 0, input_number = 0;
while(input_number &gt;= 0){
    printf("Please enter students IDs(negetive to stop)= ");
    result = scanf("%d", &amp;input_number);

    if(result != 1){
        printf("Invalid input! try again...\n");
        continue;
    }
}
</code></pre>

<p>When the input is an int- everything works fine,</p>

<p>But when entering a char (any char the is not int),</p>

<p>The loop becomes endlessly and scanf doesn't request any input anymore.</p>

<p>DO NOT suggest I use a replacement for scanf cause it's a work for school,
and scanf must be used.</p>

<p>After entering char output:</p>

<pre><code>Please enter students IDs(negetive to stop)= 4
Please enter students IDs(negetive to stop)= 5
Please enter students IDs(negetive to stop)= r
Please enter students IDs(negetive to stop)= Invalid input! try again...
Please enter students IDs(negetive to stop)= Invalid input! try again...
Please enter students IDs(negetive to stop)= Invalid input! try again...
Please enter students IDs(negetive to stop)= Invalid input! try again...
Please enter students IDs(negetive to stop)= Invalid input! try again...
Please enter students IDs(negetive to stop)= Invalid input! try again...
...
</code></pre>
