Huh... I learned this 9/15/2025:
Suppose you read a line from a file that looks like this:
Variable: A string with spaces
Normally, programmers would read characters until finding the colon, store them in a buffer, skip the colon, skip spaces, then read characters into a buffer until the EOL marker.
Guess what: there's an easier way. This looks weird, but...
char name[ 32 ]; char value[ 128 ]; sscanf( "Variable: a string with spaces", "%[^:]: %[^\n]", name, value );
The secret is in that format string. The string %[^:]: says, "read all characters until the colon as a single string, then read (and ignore) the colon." Then, the string %[^\n] says, "read all characters until the newline into a single string.
This has existed since 1978. it was standardized into ANSI C in C89/C90, still supported in C99/C11/C17, and required in POSIX! But good luck finding it in moet "Learn to Program in C" books!