gpt4 book ai didi

c++ - Arduino 字符串用逗号分隔到数组

转载 作者:太空宇宙 更新时间:2023-11-04 02:04:54 24 4
gpt4 key购买 nike

我正在尝试使用 Arduino 对红外 Remote 进行一些原始数据处理。

unsigned int ArrayKey[68] = {30868,8900,4400,600,500,600,...,600};
irsend.sendRaw(ArrayKey,68,38);

现在我尝试通过串行获取原始红外数据,但存在语法问题:

readString = 30868,8900,4400,600,500,600,1650,600,550,....

unsigned int ArrayKey[68] = {strtok(readString, ",")};

错误:无法将参数“1”的“String”转换为“char”到“char* strtok(c​​har*, const char*)”*

最佳答案

你不能像那样初始化它(非常量、不兼容等),而是可以在运行时进行初始化

char *tmp;
int i = 0;
tmp = strtok(readString, ",");
while (tmp) {
ArrayKey[i++] = atoi(tmp);
tmp = strtok(NULL, ",");
}

关于c++ - Arduino 字符串用逗号分隔到数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21946585/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com