You can use an asterisk ( * ) to convey the specifier / precision of the width of printf() , rather than hard-coded it into a format string, i.e.
void f(const char *str, int str_len) { printf("%.*s\n", str_len, str); }
AusCBloke Oct 26 '11 at 5:59 a.m. 2011-10-26 05:59
source share