Keep Leading zeros C

后端 未结 2 1961
故里飘歌
故里飘歌 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条回答
  •  萌比男神i
    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.

提交回复
热议问题