Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 获取Arduino中字符缓冲区的最后9位_String_Arduino_Charat - Fatal编程技术网

String 获取Arduino中字符缓冲区的最后9位

String 获取Arduino中字符缓冲区的最后9位,string,arduino,charat,String,Arduino,Charat,在我以前的代码中,我使用下面的代码行获取“command”字符串的最后9位数字 现在我正在使用一个char缓冲区(char packetBuffer[UDP_TX_PACKET_MAX_SIZE];),由于packetBuffer不是字符串,所以使用上述代码不起作用,我如何才能执行此操作呢 int indexOf_for_char(const char *str, int str_length, const char *target) { // naive method for

在我以前的代码中,我使用下面的代码行获取“command”字符串的最后9位数字


现在我正在使用一个char缓冲区(char packetBuffer[UDP_TX_PACKET_MAX_SIZE];),由于packetBuffer不是字符串,所以使用上述代码不起作用,我如何才能执行此操作呢

int indexOf_for_char(const char *str, int str_length, const char *target) {
    // naive method
    for (int index = 0; index < str_length; index++) {
        int j;
        // check if matched
        for (j = 0; target[j] != '\0' && index + j < str_length && str[index + j] == target[j]; j++);
        // if matched, return the index
        if (target[j] == '\0') return index;
    }
    return -1;
}

packetBuffer[28]
这样简单的订阅难道不起作用吗?
int indexOf_for_char(const char *str, int str_length, const char *target) {
    // naive method
    for (int index = 0; index < str_length; index++) {
        int j;
        // check if matched
        for (j = 0; target[j] != '\0' && index + j < str_length && str[index + j] == target[j]; j++);
        // if matched, return the index
        if (target[j] == '\0') return index;
    }
    return -1;
}
if(indexOf_for_char(packetBuffer, UDP_TX_PACKET_MAX_SIZE, "kitchen light: set top color") >=0) 
{OnColorValueRed = (packetBuffer[28]- 48)*100 + (packetBuffer[29]- 48)*10 + (packetBuffer[30]- 48);}