#include
#include
int main()
{
char *c;
sprintf(c, "03203");
return strlen(c);
}
2006-06-16 02:52:51
·
answer #1
·
answered by waylandbill 3
·
0⤊
1⤋
Well, an integer can't have a leading 0, so your number is 3203, and it's "length" is 4, not 5. If you have a leading 0, then it is stored in a character array, and you can simply use strlen() to get the length of the string. The fact that it is an "id number", and consists of all digits, doesn't matter. It's how it is stored that makes the difference.
To get the number of digits in an integer, simply use the log10() function.
int x = 4321;
int b = (int) log10((double) x);
b should be 4.
2006-06-15 15:41:20
·
answer #2
·
answered by Flyboy 6
·
0⤊
0⤋
You may need to convert it to a string for this to work...
int count = 0;
int i;
for (i = 0; your_id_number[i] != '\0'; i++)
{
count++;
}
count will return the length of your_id_number.
2006-06-15 13:59:25
·
answer #3
·
answered by senormooquacka 5
·
0⤊
0⤋