c语言输出格式问题

chen16501560 2012-01-05 11:44:43
sprintf(cTemp, "%.*d%s", 3-strlen((*itIpSplit).c_str()), 0, (*itIpSplit).c_str());

// %.*d%s 求高手指点。
...全文
193 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
IVERS0N 2012-01-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 bruceteen 的回复:]

%.*d%s 求高手指点。

--- %s也不懂?那就没办法了

而对于 %.*d,
%.1d %.2d %.3d 你懂吗?
如果懂的话,现在就是将 1 2 3 换成*号,用参数决定其值,也就是 3-strlen((*itIpSplit).c_str())
[/Quote]

学习了
gqjjqg 2012-01-05
  • 打赏
  • 举报
回复
.* 指定 %d 的精度数 为3-strlen((*itIpSplit).c_str())
bruceteen 2012-01-05
  • 打赏
  • 举报
回复
%.*d%s 求高手指点。

--- %s也不懂?那就没办法了

而对于 %.*d,
%.1d %.2d %.3d 你懂吗?
如果懂的话,现在就是将 1 2 3 换成*号,用参数决定其值,也就是 3-strlen((*itIpSplit).c_str())
chen16501560 2012-01-05
  • 打赏
  • 举报
回复
printf("%.0d",0);竟然没输出结果。
chen16501560 2012-01-05
  • 打赏
  • 举报
回复
知道了。谢谢
看1楼不爽,就不给你分了。
WYJXHL97 2012-01-05
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhao4zhong1 的回复:]
查MSDN是Windows程序员必须掌握的技能之一。
mk:@MSITStore:C:\MSDN98\98VS\2052\vccore.chm::/html/_crt_printf_width_specification.htm
printf Width Specification
The second optional field of the format specification i……
[/Quote]

子达如何 2012-01-05
  • 打赏
  • 举报
回复
楼上的正解
赵4老师 2012-01-05
  • 打赏
  • 举报
回复
查MSDN是Windows程序员必须掌握的技能之一。
mk:@MSITStore:C:\MSDN98\98VS\2052\vccore.chm::/html/_crt_printf_width_specification.htm
printf Width Specification
The second optional field of the format specification is the width specification. The width argument is a nonnegative decimal integer controlling the minimum number of characters printed. If the number of characters in the output value is less than the specified width, blanks are added to the left or the right of the values — depending on whether the – flag (for left alignment) is specified — until the minimum width is reached. If width is prefixed with 0, zeros are added until the minimum width is reached (not useful for left-aligned numbers).

The width specification never causes a value to be truncated. If the number of characters in the output value is greater than the specified width, or if width is not given, all characters of the value are printed (subject to the precision specification).

If the width specification is an asterisk (*), an int argument from the argument list supplies the value. The width argument must precede the value being formatted in the argument list. A nonexistent or small field width does not cause the truncation of a field; if the result of a conversion is wider than the field width, the field expands to contain the conversion result.

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧