0

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'.

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
Mehdi
  • 83
  • 1
  • 2
  • 7

1 Answers1

1

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]);
Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
  • Thank you for your answer, but if I want to get only the saved char, like only Tx, because i want to use it later, what should I consider ? because with the code you have provided i believe i can only print it ,i want it as a saved variable? Thank you – Mehdi Dec 01 '15 at 22:11
  • What do you think `array` is? – Iharob Al Asimi Dec 01 '15 at 22:45