Convert characters to number.

Implement function to convert characters to integer number with any base.

C++:
01 int myAtoi(char* A, int base)
02 {
03     int a=0;
04     int index=0;
05     int s=1;
06     if(A[0]==‘-‘){
07         s=-1;
08         index++;
09     }
10     while(A[index]!=‘\ 0’)
11         a=a*base+A[index++]‘0’;
12     return s*a;
13 }
Advertisements
This entry was posted in Array and linked list, String. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s