在scanf中的格式说明在C布尔数据类型 [英] Format specifier in scanf for bool datatype in C

查看:702
本文介绍了在scanf中的格式说明在C布尔数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的用C std99其定义在&LT定义数据类型BOOL; stdbool.h> 。现在,我希望用户给我输入。什么格式说明我必须scanf函数使用输入1字节的布尔值从用户,然后在我的节目结束之后操纵它。

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.

推荐答案

有是没有的。

使用一个临时对象 _Bool 的大小依赖于实现。

Use a temp object as the size of _Bool is implementation dependent.

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

bool b;
int temp;

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

这篇关于在scanf中的格式说明在C布尔数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆