How can I convert a number char in a buffer to an int.
I use:
char *buffer = somebuffer;
int number;
number = int(buffer[i]); // pointer to a number stored as a char
However, this returns the decimal code (e.g. if buffer[i] = '2', number = 50).
How can I interpret this char number as an int?
You can subtract your char code from the character code for
0(character codes for numbers are sequential and run from 0 (ascii 48) – 9 (ascii 57)). Be sure to useisdigitfirst to check the char isn’t outside the range'0'–'9'