linux中的printf问题

以下是一个简单的程序,可在HP& Linux操作系统.
但是,行为是不同的.
我不想让问题更大,但实际发生这个问题的程序在字符串中有浮点值,因此使用%f不是一个选项(即使使用sprintf).

有没有人遇到过这个?哪种行为是正确的?

这应该不是编译器问题,但仍然在gcc,icpc,icc,g上尝试过.

#include <stdio.h>

int main()
{
   printf("%s = [%010s]\n","[%010s]","1.2");
   return 0;
}

**HP:**
cc test2.c -o t ; ./t
[%010s] = [00000001.2]

**Linux:**
icc test2.c -o t ; ./t
[%010s] = [       1.2]

编辑:非常感谢你们的回复:)

解决方法

从glibc 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,and X),the 0 flag  is
          ignored.  For other conversions,the behavior is undefined.

所以带有s的0标志不能指望在基于glibc的系统上用0填充字符串.

相关文章

/etc/sysctl.conf这个目录主要是配置一些系统信息,/etc/sys...
1.作用 useradd或adduser命令用来建立用户帐号和创建用户的起...
它们都是多模式编辑器,不同的是vim 是vi的升级版本,它不仅...
不管是我们在安装软件还是监测软件的使用性能,我们都要随时...
装好Tomcat7后,发现除了本机能访问外界访问不了,岂有此理。...
修改防火墙配置需要修改 /etc/sysconfig/iptables 这个文件,...