strcpy or memcpy?

I am still learning to NOT use String class. My project is now over 400 lines of code, so just a warning if you want to see the whole sketch.

The question- When do I want to use memcpy or strcpy?

Here's my function where the question appears. Near the bottom is both strcpy and memcpy. They both do the same result. When should I use one over the other?

(incomingMessage is a global char[20])


// ========================  mqtt callback ========================
// This function is executed when some device publishes a message to a topic that this ESP8266 is subscribed to.
void callback(String topic, byte * payload, unsigned int length) {
  char message[length + 1];

  // convert the payload from a byte array to a char array
  memcpy(message, payload, length);

  // add NULL terminator to message, making it a correct c-string
  message[length] = '\0';

  Serial.print(F("Message arrived on topic: "));

  Serial.print("message: ");
  Serial.print(F("Length= "));

  //strcpy(incomingMessage, message);
  memcpy(incomingMessage, message, length);

  if (topic == incomingTopic) {
    ringFlag = true;                          //  Start ringing the phone


strcpy is for when you are copying C style strings. memcpy is for when you're copying something that isn't necessarily NULL terminated.

strcpy() will automatically copy the terminating null character of the source string and requires no length parameter to be passed to it as it recognises the end of the string by using the null character

memcpy() on the other hand requires you to pass the number of bytes to be copied and if you are copying a string it is up to you to allow for the terminating null character in the length to be copied

Thanks, both of you. I appreciate your leading me on the journey to Not String.