Reputation: 5371
I was reading a book and came across a program to read entries from a /proc
file.
The program which they mentioned has following line
printf("%.*s", (int) n, line);
I am not clear with meaning of above line
"%.*s
used instead of %s
The code can be read here
Upvotes: 3
Views: 142
Reputation: 399863
The cast expression (int) n converts the value of n
to type int
. This is because the formatting specifier requires a plain int
, and I assume (since you didn't include it) the variable n
has a different type.
Since a different type, like size_t
might have another size, it would create problems with the argument passing to printf()
if it wasn't explicitly converted to int
.
Upvotes: 0