Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   How to check whether a string is number (http://www.go4expert.com/forums/check-string-t8265/)

qiqinuinaifen128 15Jan2008 13:29

How to check whether a string is number
 
if i have a string, how do i check whether the string is number?

technosavvy 15Jan2008 15:18

Re: How to check whether a string is number
 
look for atoi() function...
it will return zero if it is not able to convert the string passed into number..

though if you have an alphanumeric inputs (like 1234go4expert)..u should go for strtol()..

both the functions even convert the input passed into their respective numbers(if possible).

Salem 15Jan2008 15:24

Re: How to check whether a string is number
 
You should use strtol() all the time.
atoi() for example cannot detect numeric overflow.

technosavvy 15Jan2008 15:30

Re: How to check whether a string is number
 
completely agree..
there is another kind of case ..when input is "1234forum"
atoi() will return 1234..!!

and in case of strtol() using the third argument we can check if the function traversed the whole input or not..

qiqinuinaifen128 15Jan2008 16:23

Re: How to check whether a string is number
 
Thank you so much. I will try it


All times are GMT +5.5. The time now is 07:52.