Keep Leading zeros C

后端 未结 2 1928
故里飘歌
故里飘歌 2021-01-25 03:22

I am trying to read the memory addresses from /proc//maps and I use the following code

for (ptr = NULL; getline(&ptr, &n, file) > 0;)     {
   if (ptr         


        
相关标签:
2条回答
  • 2021-01-25 04:02

    You're reading these values into integers; integers don't have leading zeros.

    If you know how many digits you want to pad out the length to, you can specify that in your format string:

    printf("r0: %08lx, r1: %08lx\n", r0, r1);
    

    There's no way to store and recall the exact number of leading zeroes without storing the value in a different format (e.g, a string), though.

    0 讨论(0)
  • 2021-01-25 04:20

    Use the 0 flag (which specifies leading zeros), followed by the padded length.

    printf("r0: %08lx, r1: %08lx\n", r0, r1);
                 ^^         ^^
    

    This link is a good reference to look at.

    0 讨论(0)
提交回复
热议问题