【发布时间】:2012-10-06 21:45:47
【问题描述】:
我在 C std99 中使用 bool 数据类型,其定义在 <stdbool.h> 中定义。现在我希望用户给我输入。我必须在 scanf 中使用什么格式说明符来输入来自用户的 1 字节的布尔值,然后在我的程序中对其进行操作。
【问题讨论】:
-
pranavk,你能接受@ouah 的回答吗?它似乎回答了你的问题。
标签: c scanf format-specifiers
我在 C std99 中使用 bool 数据类型,其定义在 <stdbool.h> 中定义。现在我希望用户给我输入。我必须在 scanf 中使用什么格式说明符来输入来自用户的 1 字节的布尔值,然后在我的程序中对其进行操作。
【问题讨论】:
标签: c scanf format-specifiers
没有。
使用临时对象,因为_Bool 的大小取决于实现。
#include <stdbool.h>
#include <stdio.h>
bool b;
int temp;
scanf("%d", &temp);
b = temp;
【讨论】: