Hi,

Could anyone please tell me how should I concatenate the below two:

unsigned char byte2[1]="0X";
unsigned char byte0[6];
byte0="29";

Recommended Answers

All 4 Replies

>>unsigned char byte2[1]="0X";
Wrong. You tried to stuff two characters in an array that can only hold one. Something like me trying to stuff my gut into pants that are too small.

You didn't say whether you are allowed to use standard C functions or not. If you are, then use strcat() -- look it up if you don't know how to use it.

When I use strcat I get the below error:
invalid conversion from 'unsigned char*' to 'const char*'
error: initializing argument 2 of 'char* strcat(char*, const char*)'

When I use strcat I get the below error:
invalid conversion from 'unsigned char*' to 'const char*'
error: initializing argument 2 of 'char* strcat(char*, const char*)'

Post the code.

I think you are initializing the arrays as pointers. Do it as:

unsigned char byte0[2];
strcpy(byte0, "0x");

instead. But this does not consider the nullterminator, so the array should have size 3.

unsigned char byte0[3];

Also, I don't know if strcat() takes unsigned characters. Try with just char, or by doing a typecast.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.