# Thread: char array string > integer

1. ## char array string > integer

im sure this has been answered before on here, however after searching using the keyword 'convert' and going through half an hours worth of replies my question wasnt answered.

im trying to convert a char array ( of numbers like
[7][2][6][4][5][6]) to one whole integer like 726456 (decimal)
(which have been converted from ascii to dec)

so i can perform maths calculations on the integers then output result to screen.

is there an easier way other than looping through each element, adding the column, if greater than 10, carry etc

atoi will not work as i just get zero because it expects ascii as input, is there a version of atoi for my question?

luigi

2. Basic method.

int total = 0;
A:
Multiple total by 10 and store in total
Add the number ( think char - '0' )
Go back to A and repeat until there are no more characters

total is now the value

Code:
```int total=0;

total *= 10;
total += 7;
total *= 10;
total += 2;
total *= 10;
total += 6;
total *= 10;
total += 4;
total *= 10;
total += 5;
total *= 10;
total += 6;

printf("%d\n", total);```

3. Why don't you just use atoi?

Quzah.