Casting boolean as string
Didn't think I'd be back again this quickly, guess my recall isn't what I'd hoped it would be.
How do a write the value of a boolean variable to a log as a string? I'd like to see the word 'True' or 'False' in my log.
This code is giving me a compile warning of:
different types for formal and actual parameter 2
because the second parameter I'm passing is a Boolean and it's expecting a string. So I guess I'm asking, how do I cast the boolean variable GbCEPSecurity as a String?
quzah is correct, but not entirely helpful in this case
What quzah gave you will work, but if you don't understand what his code does, it won't help you in solving the problem in the future.
is a conditional expression where if the value of b (which can be an arbitrary boolean expression) is true, the value of the construct is the expression following the question mark (in this case, a pointer to a nul terminated char array containing the string "true"), and if b is false the expression has the value of the expression following the colon (in this case, a pointer to a nul terminated char array containing the string "false"). Look up "conditional expression" in your C language reference.
b ? "true" : "false"
The answer to this is "no". You can simply use a conditional expression wherever you want to do the conversion of a boolean to a string. If you do it more than once, though, a function will be more code-space efficient. You could write your code as:
Are you saying I need to write my own function to do this?
ShLogWrite("_CINSRCH", GbCEPSecurity ? "true" : "false");