Re: a question abou "atoi"



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.

.