Counting the number of inegers in a number
Good morning all,
I am trying to created a code that counts the number of integers in a given number. For example, 12345= 5. I am stuck trying to get the counter to work properly. The code has more to it in the long run, but I don't want to bother with the rest til this counter is corrected.
I am currently getting an infinite loop, although it is giving me the answer I want. I cannot use anything other than <stdio.h> and basic loops.
Here is what I have so far:
Code:
#include<stdio.h>
int main(void)
{
long int num, ssn=1;
int i, lim=10;
printf("Enter 9 digit SSN: ");
scanf("%d",&ssn);
for(i=1; ssn>0; i=i+1)
{
ssn=ssn%10;
}
printf("You have entered %d digits. A SSN has 9 digits\n", i);
return(0);
}
Any suggestions would be greatly appreciated.