I want to get from a string a boolean value. the string looks like that:
char *s = "value=TRUE";
the value could be TRUE, FALSE, true or false
I m wondering if there is a format specifier to get directly the boolean value from the string? I do not need to pass throught a string and then deduce the boolean value.
I m looking for something like that
bool x;
sscanf(s,"value=%b",&x);
the question is. Is it possible to get the bool value directly with sscanf and with a format specifier?
If not, Are there a quick method for that?
Edit:
Based on the response there is no direct format specifier.
Here a after a quick method to get the boolean value directelly
char b[8];
if ( sscanf(s,"value=%[TtRrUuEe]",b))
return TRUE;
else
return FALSE;
I know that the above method is limited. How ameliorate it?
Note: the default value is False in case the value string contains garbage
the short answer is “no”.
You could get the source for GNU C-library and change that for yourself.
f.e.