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

前端 未结 4 1602
天涯浪人
天涯浪人 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:04

    One way of doing this is to use an snprintf-equivalent on a character array buffer, in order to create your printf format string. (Be sure to check for buffer overflows, of course.)

提交回复
热议问题