How to pass parameter n to printf(“%nd”, some_int);

前端 未结 4 1601
天涯浪人
天涯浪人 2021-01-17 15:29

We all know in C-based languages, printf(\"%11d\", some_int); means right align within an 11 character field, but what if I want to replace this constant 1

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-17 16:18

    You are going to read the printf(3) man page and come across the following:

    Instead of a decimal digit string one may write "*" or "*m$" (for some decimal integer m) to specify that the field width is given in the next argument, or in the m-th argument, respectively, which must be of type int.

提交回复
热议问题