[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

converting from char to int

Posted on 1998-08-31
5
Medium Priority
?
207 Views
Last Modified: 2010-04-02
G'day,
I am in need of a method of converting a string to an integer.
Thanks,
Andrew
0
Comment
Question by:galdes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 6

Expert Comment

by:snoegler
ID: 1171776
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
 
LVL 23

Expert Comment

by:chensu
ID: 1171777
sscanf is also able to do so.
0
 

Accepted Solution

by:
decornez earned 40 total points
ID: 1171778
For the purpose of locking.
Agree with snoegler & chensu.
can also use atof() to convert to double.
Cheers.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1171779
If you are using Borland C++ use StrToInt("12");

Regards,
Viktor Ivanov
0
 
LVL 84

Expert Comment

by:ozo
ID: 1171780
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question