How to enable printf() function from printing Boolean types in C with defining new identifier in printf("%ex",test())? -
this question has answer here:
- what printf format specifier bool? 8 answers
i trying add new identifiers printf() function enable printing "true" , "false" .. eg:printf("%boolean",test()); possible in c ?
#include<stdio.h> typedef int boolean; #define true 1 #define false 0 boolean test(int x){ return x%2==0?1:0; } int main(){ printf("%s",test(5)); system("pause"); return 0; }
change
printf("%s",test(5));
to
printf("%s",(test(5))?"true":"false");
which tells %s
print "true"
if test(5)
returns non-zero integer , "false"
if test(5)
returns 0.
Comments
Post a Comment