gpt4 book ai didi

c - C中的 "%02s"和 "%2s"有什么区别?

转载 作者:行者123 更新时间:2023-12-02 08:40:14 24 4
gpt4 key购买 nike

我有以下代码:

char temp[32] = "";
sprintf(temp, "%02s", "A");

但它有警告:Warning 566: Inconsistent or redundant format char 's',然后我将代码更改为:sprintf(temp, "%2s", "A");,警告消失了,有什么区别?

最佳答案

%0 格式表示“0-padding”,但您不能将其与未定义的字符串格式说明符 (s) 结合使用。

参见 the manual page :

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 - C中的 "%02s"和 "%2s"有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17165877/

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