I know about the introduction of the scanset with the [
conversion specifier which subsequent indicate characters to match or not to match with an additional interposition of the ^
symbol.
For this, in ISO/IEC 9899/1999 (C99) is stated:
The characters between the brackets (the scanlist) compose the scanset, unless the character after the left bracket is a circumflex (^), in which case the scanset contains all characters that do not appear in the scanlist between the circumflex and the right bracket.
So, the expression [^\n]
means, that it is scanning characters until a \n
character is found in the according stream, here at scanf()
, stdin
. \n
is not taken from stdin
and scanf()
proceeds with the next format string if any remain, else it skips to the next C statement.
Next there is the assignment-suppression-operator *
:
For this, in ISO/IEC 9899/1999 (C99) is stated:
Unless assignment suppression was indicated by a *, the result of the conversion is placed in the object pointed to by the first argument following the format argument that has not already received a conversion result.
Meaning in the case of f.e. scanf("%*100s",a);
that a sequence of 100 characters is taken from stdin
unless a trailing white-space character is found but not assigned to a
if a
is a proper-defined char
array of 101 elements (char a[101];
).
But what does now the format string "%*[^\n]"
in a scanf()-statement achieve?
Does \n
remain instdin
?
How do assignment supressor *
and negated scanset [^
work together?
Does it mean, that:
- By using
*
all characters matching to this format string are taken fromstdin
, but are sure not assigned?, and \n
isn't taken fromstdin
but it is used to determine the scan-operation for the according format string?
I know what each of those [^
and *
do alone, but not together. The question is what is the result of the mix of those two together, incorporated with the negated scanset of \n
.
I know that there is a similar question on Stack Overflow which covers the understanding of %[^\n]
only, here: What does %[^\n] mean in a scanf() format string. But the answers there do not help me with my problem.