I am trying to get input for 3 bool variables and 1 int variable. Even though I give input correctly, it is not behaving right.
I am using %d
as format specifier for bool
in stdbool.h
as suggested by @taufique in Format specifier in scanf for bool datatype in C
Here is my code and its behaviour:
#include <stdio.h>
#include <stdbool.h>
int main( )
{
bool health,sex,living;
int age;
scanf("%d%d%d%d",&sex,&health,&living,&age);
printf("\n%d %d %d %d\n",sex,health,living,age);
}
Console:
0 1 0 25
0 0 0 25
For some other Input:
1 0 0 26
0 0 0 26
But when using temporary integer variables to get input as suggested by @ouah in the same Format specifier in scanf for bool datatype in C , it works fine.
So why is scanf behaving improperly ?
PS : It does work correctly for some input:
0 0 1 26
0 0 1 26