What does “%.6d” mean in printf

前端 未结 2 1225
长情又很酷
长情又很酷 2021-02-14 11:14

What does %.6d mean in:

printf(\"%s.%.6d len:%d \", timestr, header->ts.tv_usec, header->len);

Is it a typo?

It seem

2条回答
  •  执念已碎
    2021-02-14 12:00

    The former will pad with zeros, the latter with spaces.

    #include 
    int main(void) {
        printf ("%.6d\n", 123);
        printf ("%6d\n", 123);
        return 0;
    }
    

    Produces the following output,

    000123
       123
    

提交回复
热议问题