在下面的例子中,我试图扫描一个布尔类型变量的值。当我在GCC编译时,我得到以下警告:
在C语言中有布尔类型的格式说明符吗?
warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘_Bool *’ [-Wformat=]
scanf("%d", &b);
代码:
#include <stdio.h>
#include <stdbool.h>
int main()
{
bool b;
scanf("%d", &b);
printf("%d\n", b);
}
在C语言中有布尔类型的格式说明符吗?
printf("%s\n", b ? "true" : "false");
。 - Grzegorz Szpetkowski