我有这个全局
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)
//做事
- 我的比较有什么问题(没有这个“如果”一切都很好)
- 哪个是首选 -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.
尝试检查错误行之前的字符串是否为 NULL?
关于c - 导致崩溃的基本字符串比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33056880/