Task: delete "\n" at the beginning of the array.
Example:
char s_msg[15] = "\nHello world!";
void setup()
{
Serial.begin(115200);
Serial.println("Load");
// Search \n
if(strstr(s_msg, "\n") != NULL) {
Serial.println(s_msg);
strlcpy(s_msg, &s_msg[1], sizeof(s_msg));
Serial.println(s_msg);
}
}
void loop() {}
Description: If the \ n character is present at the beginning of the message, then we copy the original character to the same character, but without \ n.
Question: is it ok to copy char to itself (s_msg is the destination buffer and the source string at the same time)
strlcpy()
should tell you. You might also look intomemmove()
andmemcpy()
. – the busybee Jan 11 '20 at 8:43