Re: a question abou "atoi"



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.
.



Relevant Pages

  • Re: Removing Certain warning
    ... Conversion from integral type to pointer type requires ... C-style cast or function-style cast ...
    (microsoft.public.dotnet.languages.vc)
  • Remove an element from a std::vector
    ... Conversion from integral type to pointer type requires ... C-style cast or function-style cast ...
    (microsoft.public.vc.stl)
  • Re: Removing Certain warning
    ... Conversion from integral type to pointer type requires ... C-style cast or function-style cast ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Possible Bug with Windows XP
    ... That does not compile, I cut-and-pasted it verbatim. ... Conversion from integral type to pointer type requires ... C-style cast or function-style cast ... This is running on Windows XP Pro and compiled with MSVC++ ...
    (microsoft.public.vc.mfc)
  • Re: Possible Bug with Windows XP
    ... That does not compile, I cut-and-pasted it verbatim. ... Conversion from integral type to pointer type requires ... C-style cast or function-style cast ... This is running on Windows XP Pro and compiled with MSVC++ 6.0. ...
    (microsoft.public.vc.mfc)