Re: a question abou "atoi"
- From: Mark McIntyre <markmcintyre@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 31 Oct 2008 15:42:00 +0000
Kelsey Bjarnason wrote:
On Fri, 31 Oct 2008 11:23:23 +0000, Mark McIntyre wrote:
66650755@xxxxxx wrote:First,thanks for all who have answered my last question.You don't need to - string[2] is already an integer type.
if char string[20]="12345";
how could I convert the string[2](that is "3") to an int by using atoi?
int x = string[2];
does the trick.
True, but the value I get here when doing this is 51; I suspect he wanted the value 3.
int x = string[2] - '0'; would do the trick.
I was kinda leaving that as an exercise for the reader, given that its an FAQ... :-)
--
Mark McIntyre
CLC FAQ <http://c-faq.com/>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
.
- References:
- Re: a question abou "atoi"
- From: Mark McIntyre
- Re: a question abou "atoi"
- From: Kelsey Bjarnason
- Re: a question abou "atoi"
- Prev by Date: Re: Judge the encode systm used by the file.
- Next by Date: Re: Where did my console output go?
- Previous by thread: Re: a question abou "atoi"
- Next by thread: Who defines the platform specific macros eg LINUX VXWORKS etc
- Index(es):
Relevant Pages
|