これは私のread_double関数です。なぜ私はflush_buff()かその効果を確認する必要がありますか?私は何とかそれを理解することはできません。私は単にflush_buff()を書いてDBL_MINを返すことができませんでしたか?どのように否定!my_function()はCで私の関数に影響を与えますか?
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;
}
flush_buff機能:それは改行(\n
)またはファイルの終わり(EOF
)のいずれかに遭遇するまで
int flush_buff(void) {
int c;
while ((c = getchar()) != '\n' && c != EOF) {}
return c != EOF;
}
BTW 'x> DBL_MAX'は決して真とならない。 – BLUEPIXY