&是什么QUOT;%* S" printf中是什么意思? [英] What does "%.*s" mean in printf?
本文介绍了&是什么QUOT;%* S" printf中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到了code段,其中有一个
I got a code snippet in which there is a
printf("%.*s\n")
什么是%。* S
意思?
推荐答案
您可以使用星号( *
)来传递宽度指定/ precision到<一个href=\"http://pubs.opengroup.org/onlinepubs/9699919799/functions/printf.html\"><$c$c>printf()$c$c>,而不是硬编码入格式字符串,即
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);
}
这篇关于&是什么QUOT;%* S&QUOT; printf中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文