When you enter something that is not a number, it scanfwill fail and leave these characters in the input. Therefore, if you enter hello, scanf will see h, reject it as invalid for the decimal number and leave it in the input. Next time through the cycle, scanfhe will see again h, so that he will simply continue the cycle forever.
fgets, sscanf. , sscanf , . fgets .
- :
char buffer[STRING_SIZE];
...
while(...) {
...
fgets(buffer, STRING_SIZE, stdin);
if ( sscanf(buffer, "%d", &price) == 1 )
break;
...
}
getchar, , \n , - (, , , ).
sscanf. , , , , . 1 , sscanf 1, .