Thursday, December 07, 2006

In order to convert char into int in C / C++, there are two methods,
1. to convert a string '1234' into integer 1234:
void main (void)
{
char c[4];
int i;
strcpy(c,"1234");
i = atoi(c);
}


2. to conver an ascii character 'q' into its decimal representation: 113
{
char c;
int i;
c='q';
i=(int)c;
}

then i will be 113.

No comments: