Re: a question abou "atoi"
- From: Kelsey Bjarnason <kelseyb@xxxxxxxxx>
- Date: Fri, 31 Oct 2008 06:28:59 -0700
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.
if char string[20]="12345";
how could I convert the string[2](that is "3") to an int by using atoi?
You don't need to - string[2] is already an integer type.
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.
.
- Follow-Ups:
- Re: a question abou "atoi"
- From: Mark McIntyre
- Re: a question abou "atoi"
- References:
- Re: a question abou "atoi"
- From: Mark McIntyre
- Re: a question abou "atoi"
- Prev by Date: Case studies for C programming.
- Next by Date: Re: (part 4) Han from China answers your C questions,
- Previous by thread: Re: a question abou "atoi"
- Next by thread: Re: a question abou "atoi"
- Index(es):