如何将printf语句格式化为列名

时间:2017-07-03 00:00:27

标签: c format printf

并非所有输出都与" column3"对齐。是否有一种特殊的方法可以减去某些数字不对齐的空格?我是否需要创建单独的printf语句?

用我的下面(可怕的)printf声明

 printf("%d \t%lf \t\t%lf \t%lf    %lf \n", i, row1[i], row2[i], row3[i], row4[i]);

以下是我得到的:

#   Column          Column1     Column2       Column3 
1   1.400000        32.300000   333.000000    66.500000 
2   11.200000       32.300000   11111.000000    35.900000
3   11.800000       32.300000   23333.000000    2.500000
4   1.500000        2.300000    32.000000    22.500000
5   1.000000        1.000000    333.000000    6.500000
6   11.000000       1.000000    3433.000000    665.500000

我怎样才能打印出来:

#   Column          Column1     Column2       Column3 
1   1.400000        32.300000   333.000000    66.500000 
2   11.200000       32.300000   11111.000000  35.900000
3   11.800000       32.300000   23333.000000  2.500000
4   1.500000        2.300000    32.000000     22.500000
5   1.000000        1.000000    333.000000    6.500000
6   11.000000       1.000000    3433.000000   665.500000

1 个答案:

答案 0 :(得分:0)

就像这样

printf("%15d\t%15lf\t%15lf\t%15lf\t%15lf\n",
    i, row1[i], row2[i], row3[i], row4[i]);