You can use an asterisk (*
) to pass the width specifier/precision to printf()
, rather than hard coding it into the format string, i.e.
void f(const char *str, int str_len)
{
printf("%.*s\n", str_len, str);
}
You can use an asterisk (*
) to pass the width specifier/precision to printf()
, rather than hard coding it into the format string, i.e.
void f(const char *str, int str_len)
{
printf("%.*s\n", str_len, str);
}