Printing leading 0's in C?

前端 未结 10 1396
[愿得一人]
[愿得一人] 2020-11-22 17:26

I\'m trying to find a good way to print leading 0\'s, such as 01001 for a zipcode. While the number would be stored as 1001, what is a good way to do it?

I thought

10条回答
  •  深忆病人
    2020-11-22 18:06

    If you need to store the zipcode in a character array zipcode[] , you can use this:

    snprintf( zipcode, 6, "%05.5d", atoi(zipcode));
    

提交回复
热议问题