The problem
I've got some byte buffer, that get's filled during runtime. I want to display the buffer's content, using hex-code. So this is the definition of the buffer:
enum { max_data_length = 8192 }; //8KB
unsigned char stream_data_[max_data_length];
Now I wanted to print the content. The data is stored for example like this:
stream_data_[0] = 124;
stream_data_[1] = 198;
stream_data_[2] = 60;
Now I want to print the contents of this buffer (in hex). I tried several stack overflow posts but they all use unsigned int or fill the arrays. I am really stuck on this problem!
The code
I tried for example:
enum { max_data_length = 3 }; //8KB
unsigned char stream_data_[max_data_length];
stream_data_[0] = 20;
stream_data_[1] = 30;
stream_data_[2] = 40;
char str[16];
sprintf(str, "%X02 ", stream_data_);
std::cout << str;
But I can't understand why the result is always different, each time I run it. For example:
C2CA426002
7C92553002