c++ - 在 Arduino 中连接字符和字符串

标签 c++ c arduino

我正在玩 Arduino 板和提供的示例。试图让我收到的消息显示在 LCD 上。我正在努力弄清楚如何使用一些预构建的代码。

我收到错误:从“const unsigned char*”到“const char*”的无效转换

我尝试修改 payload 参数类型,但它破坏了对 MessageCallback 的其他引用。

arduino 开发板文档中的 Screen.print() 定义: int print(unsigned int line, const char s, bool wrap)

代码:

static int  MessageCallback(const unsigned char *payload)
{
int result = 200;
const char screenMsg[100]; 
strcpy(screenMsg,"Set Temp: ");
strcat(screenMsg,payload);

Screen.print(1, screenMsg, true);

return result;
}

最佳答案

Strcat 的参数是(char *, const char *)。您可以通过执行“strcat(screenMsg, (char*)payload);”将“payload”转换为 char*。阅读Strcat two unsigned char in C .

关于c++ - 在 Arduino 中连接字符和字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55564174/

相关文章:

javascript - 提示文件下载 C 后端

arduino - 如何将 Arduino nano 与沁恒电子 HL-340 USB 串行适配器连接到 OpenWrt?

c++ - 是否需要在noexcept运算符中进行std::decay?

c++ - 如何检测一个成员函数是否具有特定的功能,接受特定的参数?

c - 无法调试 - 无法使用堆栈

c++ - Arduino加法作业

c++ - Arduino:将库中计算的值打印到串行监视器上

c++ - 为什么#pragma optimize ("",关闭)

c++ - 为什么在代码流中没有 delete 或 free 时在 stdc++ 库中调用 delete?

c - 切换其他人写入您的终端的权限的过程 [Unix] [C]