强制用户输入正整数并将用户置于循环中直到它们为止.
所以我希望包括不允许超过0的字符在内的所有内容
我尝试了以下方法:
while (i < 0) do {
printf("please input a number that's positive");
scanf("%d", i);
}
Run Code Online (Sandbox Code Playgroud)
对于正整数,请使用以下代码
int i;
do
{
printf("please input a number that's positive");
scanf("%d", &i);
}while (i < 0);
Run Code Online (Sandbox Code Playgroud)
c语言不提供用户输入的错误检查.期望用户输入正确的数据类型.例如,如果用户在预期整数值时输入了字符,则程序可能会进入无限循环或异常中止.