|
-
February 6th, 2005, 11:59 AM
#1
converting char[2] to an int, is it possible ?
Hi !
I have a char array that contains digits such as {'0', '1'}. I want to convrt it to an int (1) like in the following code"
Code:
int main()
{
char myInts[3] = {'0','2','\0'};
int myChars = myInts;
return 0;
}
surely
Code:
int myChars = myInts;
is an error but is there a function that can make the convertion ?
Thanks !
-
February 6th, 2005, 12:03 PM
#2
Re: converting char[2] to an int, is it possible ?
Take a look at the atoi function (ansi to integer) it converts an string (that contains legal digits in ansi code) to an integer:
Code:
int main()
{
char myInts[3] = {'0','2','\0'};
int myChars = atoi(myInts);
return 0;
}
-
February 6th, 2005, 01:26 PM
#3
Re: converting char[2] to an int, is it possible ?
Thanks a lot !
-
February 6th, 2005, 05:38 PM
#4
Re: converting char[2] to an int, is it possible ?
'atoi' has some drawbacks...take a look at the following FAQ for alternatives..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|