用printf跳过参数 [英] skipping parameters with printf

查看:167
本文介绍了用printf跳过参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想知道他们是转换说明符还是其他

方法,这样我就不会使用特定的参数printf。


如果不这样做,是否允许简单地不使用参数如果

它在参数列表的末尾?

例如,


printf("%02d :%02d:%02d,小时,分钟,秒); / * 11:59:00 * /

printf("%02d:%02d",小时,分钟,秒); / * 11:59 * /

谢谢,

-


John Devereux

Hi,

I would like to know if their is a conversion specifier, or other
method, that will allow me to not use particular arguments to printf.

Failing that, is it permissable to simply "not use" the parameter if
it is at the end of the parameter list?
For example,

printf("%02d:%02d:%02d", hours, minutes, seconds); /* 11:59:00 */
printf("%02d:%02d", hours, minutes, seconds); /* 11:59 */
Thanks,
--

John Devereux

推荐答案

在文章< 87 ************ @ cordelia.devereux.me.uk> ;,

John Devereux< ; JD ****** @ THISdevereux.me.uk>写道:
In article <87************@cordelia.devereux.me.uk>,
John Devereux <jd******@THISdevereux.me.uk> wrote:
我想知道它们是否是转换说明符或其他
方法,这将允许我不使用printf的特定参数。
如果不这样做,是否允许简单地不使用参数如果它位于参数列表的末尾?
例如,
printf("%02d:%02d:%02d",小时,分钟,秒); / * 11:59:00 * /
printf("%02d:%02d",小时,分钟,秒); / * 11:59 * /
I would like to know if their is a conversion specifier, or other
method, that will allow me to not use particular arguments to printf. Failing that, is it permissable to simply "not use" the parameter if
it is at the end of the parameter list? For example, printf("%02d:%02d:%02d", hours, minutes, seconds); /* 11:59:00 */
printf("%02d:%02d", hours, minutes, seconds); /* 11:59 */




回答你的第二个问题:当printf()和kin达到转换规范的

结尾时,他们停止尝试转换

值,所以你的第二个例子没问题。


回答你的第一个问题:C89标准不提供任何

机制跳过值或将它们无序转换。


printf系列有一个共同的扩展名,它在%之后立即提供一个

前缀,由一个参数组成数字

后跟



Answering your second question: when printf() and kin reach the
end of the conversion specification, they stop attempting to convert
values, so your second example will be fine.

Answering your first question: The C89 standard does not offer any
mechanism to "skip" values or convert them out of order.

There is a common extension to the printf family which offers a
prefix immediately after the %, consisting of an argument number
followed by a


,当出现时,指定的值是

下一个转换后的值。请注意,
and when this appears, the specified value is the
next one converted. Note that


不是标准C

字符集的一部分,因此这个扩展名是双重不可移植的。

- -

任何足够老的bug都会成为一个功能。
is not a part of the standard C
character set, so this extension is doubly non-portable.
--
Any sufficiently old bug becomes a feature.


这篇关于用printf跳过参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆