I'm sorry, I wasn't quite clear on your restrictions. This is the strictest format string you can give sscanf in order for it to work properly.
Originally Posted by Nazgulled
I am sorry, but the bracket identifier is more strict than %c or %s in both cases, since sscanf first reads two digits separated by a comma, a double quote and does nothing with it, then reads everything up to but excluding the next quote, then reads the quote and does nothing with it, then a comma, then a h or v. It fails if it doesn't match exactly. Pretty sweet!
int num, num2;
char matchme="31,3,\"Fun in the sun\",v", str, ch;
if (sscanf(matchme, "%d,%d,\"%[^\"]\",%1[hv]", &num, &num2, str, ch ) < 4 )
printf("Error reading string.\n");
char foo = ch;
printf("%d %d %s %c\n", num, num2, str, foo);
The bracket identifier also requires a char array that must be large enough to hold all the input it should read and a terminating NUL. Why is it a problem for you to just take ch and assign the first argument to a normal char? It's not that hard or evil.