This is my read_double function. Why do I have to check for !flush_buff() or what is its effect? I somehow cannot figure it out. Couldn't I just write flush_buff() and then return DBL_MIN?
double read_double(void) {
double x;
int c, status;
printf("Insert double: ");
status = scanf("%lf", &x);
if (status == EOF || (c = getchar()) == EOF) {
return DBL_MIN;
}
if (status != 1 || c != '\n' || x < DBL_MIN) {
if (!flush_buff()) { /*What is the purpose of this?*/
return DBL_MIN;
}
return DBL_MAX;
}
return x;
}
The flush_buff function:
int flush_buff(void) {
int c;
while ((c = getchar()) != '\n' && c != EOF) {}
return c != EOF;
}