Format specifier in scanf for bool datatype in C

pranavk picture pranavk · Oct 16, 2012 · Viewed 34.3k times · Source

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.

Answer

ouah picture ouah · Oct 16, 2012

There is none.

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;