小编Joh*_*ohn的帖子

发生错误时Scanf返回1而不是0

我已经读过,返回的值scanf指示它是否能够读取和转换值。我已经使用返回值来检测输入是否为整数,但是输入是否4.5 scanf返回1而输入是否g scanf返回0。她是我的代码:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x;
    int ReturnedValue=scanf("%d",&x);
    printf("Scanf Returned:%d",ReturnedValue);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在多篇不同的文章中,您建议使用返回的值scanf检测整数,但是为什么现在不起作用?

c return input scanf c99

2
推荐指数
1
解决办法
45
查看次数

标签 统计

c ×1

c99 ×1

input ×1

return ×1

scanf ×1