Trying to covert a byte array to a char

I have a byte array with decimals representing characters and I need to build a char array

bytes[0] = 75
bytes[0] = 114
bytes[0] = 105
bytes[0] = 115

results needs to be "Kris"

Seems easy but I can't figure it out

TIA

char stng[4];
 uint8_t bytes[4];

 bytes[0] = 75;
 bytes[1] = 76;
 bytes[2] = 77;
 bytes[3] = 78;

 for (i = 0; i < 4; i++) {
   strcat(stng, (char)bytes[i] );
 }

 Serial.println(stng);

Something like this?

uint8_t bytes[] = {75, 114, 105, 115};

char stng[5]{};  // Reserve one position for the termination character.
memcpy(stng, bytes, sizeof(bytes));
Serial.println(stng);
1 Like

Yes, thanks a million!

Would you mind flagging the most helpful post as the solution? This prevents helpers spending time on a solved issue and it will lead people with the same question to the correct answer directly.

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project :wink: See About the Installation & Troubleshooting category.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.