Let's have this code
char input[] = "key: value";
char key[32], value[32];
sscanf(input, "%31[^:]:%*[ ]%31s", key, value);
There can be zero or more spaces after the :
, I'd like to store the key ond value into c-string variables. The code above can work with one or more spaces, but tough luck with zero spaces.
Is there a simple way how to parse such strings? No necessarily sscanf, but I'd like to avoid regex.
Edit
I found a reference supporting the accepted answer (what an useful, but non-intuitive feature):
the function will read and ignore any whitespace characters encountered before the next non-whitespace character (whitespace characters include spaces, newline and tab characters -- see isspace). A single whitespace in the format string validates any quantity of whitespace characters extracted from the stream (including none).