【问题标题】:Format specifier in scanf for bool datatype in Cscanf 中用于 C 中 bool 数据类型的格式说明符
【发布时间】:2012-10-06 21:45:47
【问题描述】:

我在 C std99 中使用 bool 数据类型,其定义在 <stdbool.h> 中定义。现在我希望用户给我输入。我必须在 scanf 中使用什么格式说明符来输入来自用户的 1 字节的布尔值,然后在我的程序中对其进行操作。

【问题讨论】:

  • pranavk,你能接受@ouah 的回答吗?它似乎回答了你的问题。

标签: c scanf format-specifiers


【解决方案1】:

没有。

使用临时对象,因为_Bool 的大小取决于实现。

#include <stdbool.h>
#include <stdio.h>

bool b;
int temp;

scanf("%d", &temp);
b = temp;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-08
    • 2021-11-23
    • 2021-08-26
    • 2023-03-10
    • 2016-07-29
    • 1970-01-01
    相关资源
    最近更新 更多