C画幅说明问题 [英] C format specifier question

查看:152
本文介绍了C画幅说明问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我的工作我碰到写由别人一个code。
 我看到了一个语句,

While I was working i came across a code which was written by somebody else. i see a statement as ,

sprintf(o_params->o_file_name,
        "%s_%s_%04.4d_%s_%s.ASC",
        "OUTD", "RM", sequence_no, DateStamp_buf1, TimeStamp_buf1
);

在上面的说法,我看%04.4d 。这是一个正确的格式说明?

In the above statement, I see %04.4d. Is this a correct format specifier?

变量 sequence_no 静态INT 键,它不具有小数。

The variable sequence_no is static int and it doesn't have decimal.

推荐答案

从<一个href=\"http://www.freebsd.org/cgi/man.cgi?query=printf&apropos=0&sektion=3&manpath=FreeBSD+7.2-RELEASE&format=html\"相对=nofollow> FreeBSD的联机帮助 3人的printf

可选precision,在形式
  一段时间 。后跟一个可选
  数字串。如果数字串是
  省略,precision被取为
  零。 这给了最低数量
  数字出庭D,I,O,U,
  x和X转换
的数
  位数后出现
  小数点的,A,E,E,F和F
  转化的最大数目
  对于g和G显著位
  转换,或最大数目
  待从字符串印刷的字符
  s转换。

An optional precision, in the form of a period . followed by an optional digit string. If the digit string is omitted, the precision is taken as zero. This gives the minimum number of digits to appear for d, i, o, u, x, and X conversions, the number of digits to appear after the decimal-point for a, A, e, E, f, and F conversions, the maximum number of significant digits for g and G conversions, or the maximum number of characters to be printed from a string for s conversions.

因此​​,在这种情况下,%04.4d 0.4 指定号码的所有四个数字应被打印。当然, 04 部分只是垫带前导零的数字,如果它是小于1000然而,在这种情况下,作为上述手册页的状态,

So in this case, %04.4d, the .4 specifies that all four digits of the number should be printed. Of course, the 04 part just pads the number with leading zeros if it is less than 1000. However, in this case, as the above manual page states,

'0'(零)零填充。对于除n的所有转换,转换后的
  值被填充在左边用零而
  比空白。
  如果一个precision用一个数字给定
  转换(D,I,O,U,I,X和X),0标志
  忽略

`0' (zero) Zero padding. For all conversions except n, the converted value is padded on the left with zeros rather than blanks. If a precision is given with a numeric conversion (d, i, o, u, i, x, and X), the 0 flag is ignored.

由于想必所有四个数字将被印无论如何,我的猜测是,这只是一个吃剩的或错字或东西。该语法产生编译器警告与的gcc -Wall (见思南Unur的例子),但它似乎并没有成为一个真正的错误。

Since surely all four digits would be printed anyway, my guess would be that it was just a leftover or typo or something. This syntax produces compiler warnings with gcc -Wall (see Sinan Unur's example) but it does not seem to be an actual error.

这篇关于C画幅说明问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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