gpt4 book ai didi

c - 警告 : '0' flag ignored with precision and ‘%i’ gnu_printf format

转载 作者:行者123 更新时间:2023-12-04 06:52:28 24 4
gpt4 key购买 nike

使用 gcc 4.4.1 在 Ubuntu Karmic 上编译一些旧版 C 代码时,我收到以下警告

警告是:

src/filename.c:385: warning: '0' flag ignored with precision and ‘%i’ gnu_printf format



导致发出警告的代码段是:
 char     buffer[256] ;
long fnum ;
/* some initialization code here ... */
sprintf(buffer, "F%03.3i.DTA", (int)fnum); /* <- warning emitted here */

我想我理解这个警告,但我想在这里检查一下我是否正确,以及解决这个问题的(确定的)正确方法。

最佳答案

来自 printf(3)手册页:

   0      The value should be zero padded.  For d, i, o, u, x, X, a, A, e,
E, f, F, g, and G conversions, the converted value is padded on
the left with zeros rather than blanks. If the 0 and - flags
both appear, the 0 flag is ignored. If a precision is given
with a numeric conversion (d, i, o, u, x, and X), the 0 flag is
ignored. For other conversions, the behavior is undefined.

因此,您可以使用零填充或最小位数,但不能同时使用两者。

关于c - 警告 : '0' flag ignored with precision and ‘%i’ gnu_printf format,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2927513/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com