Looks like this is my week for questions, most of them probably have really easy answers.
I have allocated a char array as follows
char mArr[4] = {'0','0','0','0'};
itoa(data,&mArr,10);
But when it is displayed it shows a load of garbage.
When I display it to the screen, it shows 0002IIIIIIIITM/
I was expecting the 0002, but the rest is just garbage, and I don't see where it has come from when the array is explicity declared as 4 bytes, and data is a single 16 bit integer.
I have tried rewriting the code with a '\n' for the end of string, and making the array 5 cells, but it makes no difference.
I apologise if this is a real noddy question, but I usually use std::string, but want to use char[] here, and need to understand what I am doing wrong.
TIA,
K
I have allocated a char array as follows
char mArr[4] = {'0','0','0','0'};
itoa(data,&mArr,10);
But when it is displayed it shows a load of garbage.
When I display it to the screen, it shows 0002IIIIIIIITM/
I was expecting the 0002, but the rest is just garbage, and I don't see where it has come from when the array is explicity declared as 4 bytes, and data is a single 16 bit integer.
I have tried rewriting the code with a '\n' for the end of string, and making the array 5 cells, but it makes no difference.
I apologise if this is a real noddy question, but I usually use std::string, but want to use char[] here, and need to understand what I am doing wrong.
TIA,
K