字符串末尾无法识别 [=10=]1[=10=]0..?

Unrecognized \001\000 at the end of string..?

我使用 NRF24L01 模块与 2 个 arduino 通信..

我发这个:

const char hello[32];
memcpy(hello, "World", 5);

现在,我在另一边收到这个:

"World[=24=]1[=24=]0[=24=]0[=24=]0"

我怎样才能清理我的绳子或者那是什么?

谢谢, 丹尼尔

"World"const char[6] 类型。您缺少空终止符。

https://en.cppreference.com/w/cpp/language/string_literal

您没有复制字符串文字的空终止符,因此您需要指定 6 而不是 5:

memcpy(hello, "World", 6);

只不过helloconst个字符的数组,所以实际上不能写入,只能初始化。你的memcpy()未定义的行为

改用这个:

const char hello[32] = "World";

这将初始化数组的前 5 个字符,并为您将其余字符清零。