printf
format string %.*s
takes two arguments, *
for the number and finally s
for a string, so it prints the first 7 characters of the string pointer s
. In general, anytime there is a number, you may use *
instead to read it as an argument.
%7s
would print seven characters or more if the string were longer, while %.7s
would print up to seven characters. So sometimes one would write "%*.*s", 7, 7, s
to print exactly 7 characters.
solved Can anyone explain me the working of this C code? [duplicate]