c - 导致崩溃的基本字符串比较

标签 c arduino

我有这个全局

const char PROTOCOL_SET_WIFI_CONNECTION[]= "setWifi";

//or this one
//#define PROTOCOL_SET_WIFI_CONNECTION "setWifi" 

然后当我尝试比较字符串时,我遇到了很多问题(硬件问题,例如崩溃)

char *header = strtok (incomingData,":");
if (strcmp (header,PROTOCOL_SET_WIFI_CONNECTION ) == 0) 

//做事

  1. 我的比较有什么问题(没有这个“如果”一切都很好)
  2. 哪个是首选 -define 或 const? (单片机)

最佳答案

也许是这样

Once the terminating null character of str is found in a call to strtok, all subsequent calls to this function (with a null pointer as the first argument) return a null pointer.

strtok reference

尝试检查错误行之前的字符串是否为 NULL?

关于c - 导致崩溃的基本字符串比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33056880/

相关文章:

python - 如何提高 PySerial 读取速度

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

c - 为什么C语言给字符数组赋值时没有 '&'?

c - 与堆栈指针

c - Arduino Pro 迷你启动画面

arduino - 如何使用 Nest 设置当前温度

c++ - Teensy/Arduino 库编译错误

c - 我将如何写入内存?

c - 如何在循环中读取多个输入

c - 指针的大小,C中指向指针的指针