You are reading input till a \n
into kid
with the first scanf()
. But that scanf()
won't read the \n
and it will remain in the input buffer.
When the next scanf()
is done, the first character it sees is the \n
upon which it stops reading before anything is written to color
.
You could do
scanf("%24[^\n] ", kid);
scanf("%9[^\n]", color);
The space after the [^\n]
will read a white-space character like \n
.
If %*c
is used like
scanf("%24[^\n]%*c", kid);
%*c
in scanf()
will cause a character to be read but it won't be assigned anywhere. *
is the assignment suppressing character. See here.
But if exactly 25 characters are given as input before a \n
, the %*c
will just read the last character leaving the \n
still in the input buffer.
If you can use a function other than scanf()
, fgets()
would do well.
Do
fgets(kid, sizeof(kid), stdin);
but remember that fgets()
would read the \n
as well into kid
. You could remove it like
kid[strlen(kid)-1]='\0';
Due to this \n
being read, the number characters that are read will be effectively 1 less.