I've been trying to remove all my String objects and stick with char arrays, and it has been a bit of a learning curve. Two questions. Is the following function safe, and is there something that essentially does the same thing without all my extra steps? I was looking at sprintf, but wasn't entirely confident on how to use it.
void mqttDebug(char msg[]){
char buffer [64]; // yes, could theoretically chop off lengthy messages
deviceIDLength = sizeof(deviceID); // deviceID is global char array
for(int i = 0; i < deviceIDLength ; i++){
buffer[i] = deviceID[i];
}
buffer[deviceIDLength] = ':';
buffer[deviceIDLength+1] = ' ';
for(int i = deviceIdLength + 2; i < 63; i++){
buffer[i] = msg[i];
if(msg[i] == '\0'){
break;
}
}
buffer[63] = '\0';
mqtt.publish("debug", buffer);
}