【发布时间】:2016-12-03 22:09:44
【问题描述】:
这是我的 read_double 函数。为什么我必须检查 !flush_buff() 或它的作用是什么?我不知何故无法弄清楚。我不能只写flush_buff()然后返回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;
}
flush_buff 函数:
int flush_buff(void) {
int c;
while ((c = getchar()) != '\n' && c != EOF) {}
return c != EOF;
}
【问题讨论】:
-
顺便说一句
x > DBL_MAX永远不会成为现实。
标签: c buffer eof flush negation