C语言 scanf 中的格式说明符用于 C 中的 bool 数据类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12920694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Format specifier in scanf for bool datatype in C
提问by pranavk
I am using bool datatype in C std99 whose definitions are defined in <stdbool.h>. Now I want the user to give me input. What format specifier I must use in scanf to input the boolean value of 1 byte from the user and then manipulate it afterwards in my program.
我在 C std99 中使用 bool 数据类型,其定义在<stdbool.h>. 现在我希望用户给我输入。我必须在 scanf 中使用什么格式说明符来从用户输入 1 字节的布尔值,然后在我的程序中对其进行操作。
回答by ouah
There is none.
空无一人。
Use a temp object as the size of _Boolis implementation dependent.
使用临时对象,因为它的大小_Bool取决于实现。
#include <stdbool.h>
#include <stdio.h>
bool b;
int temp;
scanf("%d", &temp);
b = temp;

