相关疑难解决方法(0)

如何在C中检查输入是否为数字?

在C的主要功能:

void main(int argc, char **argv)
{
   // do something here
}
Run Code Online (Sandbox Code Playgroud)

In the command line, we will type any number for example 1 or 2 as input, but it will be treated as char array for the parameter of argv, but how to make sure the input is a number, in case people typed hello or c?

c types

11
推荐指数
4
解决办法
11万
查看次数

scanf失败了为什么?


当我写这篇文章时,编译并运行:

int x;   
scanf ("%d", &x);  
while (x!=4) {  
    scanf ("%d", &x);  
}
Run Code Online (Sandbox Code Playgroud)

当插入char或小于4的double数时,它进入一个无限循环.
当插入大于4的double时,它会终止.
任何解释?

c scanf

2
推荐指数
3
解决办法
6089
查看次数

标签 统计

c ×2

scanf ×1

types ×1