I have a function that counts how much digits a number has, but when I put a number like "05", it recognizes just as 1 digit, in stead of 2.
#include <stdio.h>
int compd(int num)
{
int count = 0;
if(num == 0)
{
return (1);
} else
{
while(num != 0)
{
num = num/10;
++count;
}
return (count);
}
}
main()
{
int num;
scanf("%d", &num);
printf("%d", compd(num));
}
The program takes the value of the number and divides it by 10 until reaching a non-integer number. But 05 is the same as 5, in practice; dividing 05 just once by 10 it gets a decimal number, as well as 5. How to solve this bug? Thank you.