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);
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
See About the Installation & Troubleshooting category.