[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

converting from char to int

G'day,
I am in need of a method of converting a string to an integer.
Thanks,
Andrew
0
galdes
Asked:
galdes
1 Solution
 
snoeglerCommented:
use atoi() (ascii to integer)
or atol(ascii to long)

Remember:
"1234" -> 1234
"12.34"-> 12
"-1234"-> -1234
"-12.34"-> -12
"12.75"-> 12
"-12.75"-> -12

And make sure that there are no leading spaces - as far as i know it is compiler dependent
if they are omitted or if simply '0' is returned.
I'll post this as a comment as i don't know if this answers your question - but just let me know
it if i should post an answer :)
0
 
chensuCommented:
sscanf is also able to do so.
0
 
decornezCommented:
For the purpose of locking.
Agree with snoegler & chensu.
can also use atof() to convert to double.
Cheers.
0
 
viktornetCommented:
If you are using Borland C++ use StrToInt("12");

Regards,
Viktor Ivanov
0
 
ozoCommented:
decornez, what's the purpose of locking just to agree with snoegler & chensu?

(strlen and strtol also convert strings to intgers,
if the integers returned by atoi or sscanf don't happen to me the ones you want)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now