sprintf usage with %.s
c, printf
Solution
Use `*` character.
sprintf(/* ... */, "%.*s", (int) strlen(str), str);
If you use C99, `snprintf` can also be suitable.
man printf (3) The width is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted.
Problem
While using sprintf like this ``` sprintf("%.40s",str); ``` I want to give a value like strlen(str) in place of 40.How do I do that? I tried replacing 40 with strlen(str), doesn't work. Giving a value like ``` #define len strlen(str) ``` and using %.len doesnt work either since %.len is used in " ".