Re: a question abou "atoi"
- From: Mark McIntyre <markmcintyre@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 31 Oct 2008 11:23:23 +0000
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.
int a;
char string[7]="111111";
a=atoi(string[3]);
atoi takes a string, string[2] is a character - which is an integer type.
error C2664: 'atoi' : cannot convert parameter 1 from 'char' to 'const
char *'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast.
You're using a C++ compiler, don't do that if you're compiling C, the two languages are different.
.
- Follow-Ups:
- Re: a question abou "atoi"
- From: Kelsey Bjarnason
- Re: a question abou "atoi"
- Prev by Date: Re: pageup/pagedwn implementation
- Next by Date: Re: srand
- Previous by thread: Re: a question abou "atoi"
- Next by thread: Re: a question abou "atoi"
- Index(es):
Relevant Pages
|