Assign problem

How can I assign codes below to unsigned char data[8];
I couldnt assign codes below, Normally when I run the code, I can see 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 on serial port
but I must assign these characters to “data” Please help :frowning:

for(int nIndex = 0; nIndex < nMsgLen; nIndex++)
{
Serial.print(“0x”);
if(nMsgBuffer[nIndex] < 16) Serial.print(“0”);
Serial.print(itoa(nMsgBuffer [nIndex], sString, 16));
Serial.print(" ");
}

I'd probably use sprintf, but I'm not clear exactly what it is you're trying to do.

I want to assign result to variable which is coming from code below.

for(int nIndex = 0; nIndex < nMsgLen; nIndex++)
{
Serial.print(“0x”);
if(nMsgBuffer[nIndex] < 16) Serial.print(“0”);
Serial.print(itoa(nMsgBuffer [nIndex], sString, 16));
Serial.print(" ");
}

I want to assign result to variable which is coming from code below.

There is no variable coming from that code.

That code is sending data to the serial port.

So, try again. What variable do you want to assign a value to? Where is that value to come from?

PaulS:

I want to assign result to variable which is coming from code below.

There is no variable coming from that code.

That code is sending data to the serial port.

So, try again. What variable do you want to assign a value to? Where is that value to come from?

Yes, but I dont want to send this data to serial port only.. I want send this data to serial port and assign this data to "MyData" variable. For example another part of this code I want to see this data in MyData variable if I call it again.

I want send this data to serial port and assign this data to "MyData" variable.

What data? Are you referring to the string sent to the serial port? Why would you need to save that in an array? The data (the important data) is ALREADY in a variable (well, an array).