Assuming you have this:
char caracteres[10] = {'1', '2'};
If you have not already done so, you should end the string with ''0'
'
:
char caracteres[10] = {'1', '2', 'char caracteres[10] = "12";
' };
With what would be equivalent to this:
uint8_t resolucion = 0;
for( char* ptr = caracteres; *ptr; ++ptr )
{
resolucion *= 10;
resolucion += *ptr - '0';
}
The whole step is as simple as using a loop:
'9' - '0' = 9
'5' - '0' = 5
'1' - '0' = 1
'0' - '0' = 0
That is, it is iterated by the sequence of characters and each one is subtracted the digit %code% (do not forget that the character is the representation of a number). Reviewing an ASCII table is easy to see that:
char caracteres[10] = {'1', '2'};