Hello every body
i want to conver numbers :
0 , 1 , 2, 3,4 ,5 , 6, 7,8 , 9
to the following forum :
00 , 01 , 02 , 03, 04 , 05 , 06 , 07 ,08 , 09
Thanks a lot
Nada
Printable View
Hello every body
i want to conver numbers :
0 , 1 , 2, 3,4 ,5 , 6, 7,8 , 9
to the following forum :
00 , 01 , 02 , 03, 04 , 05 , 06 , 07 ,08 , 09
Thanks a lot
Nada
Nada,
If you just want to display them in this form (01, 02), do the following:
printf("%02d", 1);
this should display 01 for you. If you want more zeros, just change the field width specifier. If you make the field width 5, it will display the number padded with as many zeros as it takes to fill the field.
clu
Thanks a lot for reply
But i want to get 01 form without using printf .In anther word , i need to save number in array or any think else then when i need it i just type array name and the result apear in the follwoing form : 01 , 02, ...etc
so pllllease i need solution with out depend on printf
You will need to store the number as a string then. When a number is stored as an integer or long, it doesn't get stored with leading zeros.
int num = 0;
char str_num[3];
sprintf(str_num, "%02d", num);
Hi,
Integers are stored in bytes( 2 in the old days and now mostly 4 bytes).
In most systems they are stored low byte first.
Take a 2 byte int for instance.
The number 25 would be 19 00 HEX
The number 255 would be FF 00 HEX
Thus 256 would be 00 01 HEX
You can see that leading zero's are not part of the format for int's.
Hope this helps.
Thaaaaaaks a lot for support