【发布时间】:2020-06-19 05:30:48
【问题描述】:
为什么我放一个浮点数没有出现错误?
int m;
if(scanf("%d%",&m)!=1)
{
printf("Error\n");
exit(1);
}
【问题讨论】:
-
取决于“float”的确切给出方式:例如,“1.2”可以(正确)视为整数输入(即“1” - 忽略其余部分);但是,“.123”很可能会失败。
-
也许这篇文章:C-Checking if input (float) is purely integer or float 会有所帮助?
标签: c if-statement scanf