Originally Posted by
Bayint Naung
User enter something invalid (say number gt max) then for 2nd try,user hits EOF.
so input > max; and you are returning some value greater than max
What a superuser!
So just make a conditional return, at the end of the function. Either <min or >max could be a normal unrecoverable error. It just so happens the only unrecoverable errors are:
Code:
if (ferror (stdin) || feof (stdin)) {
clearerr (stdin);
return min - 1;
}
else {
return return_value;
}
I would stick to comparing errno with 0 or errno.h macros. errno is a standardized variable, so use your own flags rather than extending errno.