+ 3

How can i know the number of numbers of a phone number in c langage

for example how can i know that 0666666666 is a 10 numbers number

21st May 2017, 5:20 PM
Zineb Ab
Zineb Ab - avatar
9 odpowiedzi
+ 10
If the number is input as a string 'a', use strlen(a)
21st May 2017, 5:23 PM
Pixie
Pixie - avatar
+ 8
In reference to @Ace's answer, you can always take input as string, check number of chars, and then 'convert' it to int for later operations.
22nd May 2017, 5:03 AM
Hatsy Rei
Hatsy Rei - avatar
+ 7
It's better to take huge values like Phone number as string because max value of int is 2,147,483,647. Usually a phone number contains 10 digits plus a 2 digit country code. So, it is a better decision to input them as a string.
22nd May 2017, 7:18 AM
Pixie
Pixie - avatar
+ 6
int flag=0; int num=63517381; while (num>0) { flag++; num/=10; } print (flag);//idk the syntax for output in C. The output will be 8. This is how to do it with Integer input. However, I still recommend you use string input
23rd May 2017, 1:53 PM
Pixie
Pixie - avatar
+ 5
So in other words, how many digits there are in a number? Use a while loop, and see how many times it takes to divide the number before it's less than one. int numDigits = 0; int num = 135; while(num >= 1){ numDigits++; num /= 10; } Or If the number is a string (due to 0 in front), just get the string length.
21st May 2017, 5:25 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
got it thank u all 😊
23rd May 2017, 1:50 PM
Zineb Ab
Zineb Ab - avatar
0
but i have an integer, we can t get the lenght of an integer o.O .. didnt understand 😐 ..
21st May 2017, 5:52 PM
Zineb Ab
Zineb Ab - avatar