Click here to Skip to main content
15,174,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to read 10 digit mobile number in c language. I used long int and long long int and double int also but I didn't get answer.

What I have tried:

long int a ;
But I got some number which is not equal to entered number.

I also take data type as long int and long double but it generate wrong output.
Updated 1-Dec-19 22:21pm

I also take data type as long int and long double but it generate wrong output.

Never ever input a phone number as numeric because of the 0 in first position.
Use a string of char array, just like with letters.

But why? Is there any reason?

Because a phone number usually start with a '0' and international phone numbers start with a '+'. It is mainly made of digits, but not only, and it don't respect the rules of a number.
An@mik@ 31-Jul-19 13:13pm
But why? Is there any reason?
MadMyche 31-Jul-19 13:41pm
Because the first digit can be zero, which would be lopped off when stored as a numeric type.
A "mobile number" is not a "number" in the normal sense: you cannot do arithmetic with it.
What is twice my mobile number? What do you get if you add your mobile number and mine? There is no answer because the results are useless: they aren't "mobile numbers" any more.

All you can do with a mobile number is store it and retrieve it - so it's a string and should be stored as such.
In fact, it's pretty much compulsory: using a numeric field to store it will lose vital information such as the leading zero, or two leading zeros which can indicate a number in a different country: 0044 indicates the UK for example. You'll also sometimes find it entered as a +44 prefix which can't be stored in a numeric field either. When it comes to land lines as well ... it gets worse! Brackets are allowed: "+44 (0) 1234 56789" where the 0 is only reg=quired if the +44 part is not used, spaces are allowed to separate area codes from in-area numbers: "01234 46789" and so on. And some people use keypad lettering: "44-HOWS MY DRIVING" being "44-4697-69-3748464" (which if it's a real number, I'm sorry!)

So for phones, always use a string!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900