I typically acquire a character with %c
, but I have seen code that used %*c%c
. For example:
char a;
scanf("%*c%c", &a);
What is the difference?
I typically acquire a character with %c
, but I have seen code that used %*c%c
. For example:
char a;
scanf("%*c%c", &a);
What is the difference?
In a
scanf
format string, after the%
, the*
character is the assignment-suppressing character.In your example, it eats the first character but does not store it.
For example, with:
If you enter:
xyz\n
, (\n
is the new line character) thenx
will be stored in objecta
.With:
If you enter:
xyz\n
,y
will be stored in objecta
.C says specifies the
*
forscanf
this way:According to Wikipedia:
It is so you can skip the character matched by that asterisk.