I was wondering how can I convert a 6 digit number for example 198200
, to a char
for example Tx = ['1', '9', '8', '2', '0', '0']
, so that later I can for example write:
*p_tx_buffer++ = Tx[2];
And then I will only send a the '8'
.
I was wondering how can I convert a 6 digit number for example 198200
, to a char
for example Tx = ['1', '9', '8', '2', '0', '0']
, so that later I can for example write:
*p_tx_buffer++ = Tx[2];
And then I will only send a the '8'
.
A simple quick solution is
char array[100];
int number = 198200;
if (snprintf(array, sizeof(array), "%d", number) >= sizeof(array))
fprintf(stderr, "there is not enough room for the string\n");
else
fprintf(stdout, "array[2] = %c\n", array[2]);