我有一个电路,通过我的android程序中的蓝牙接受数据(特定字符数组)。
现在,我想要做的是:重新编程我的微控制器,我希望从我的微控制器接收的数组中过滤或提取一系列字符。
我的android传递了这三种char数组:
1. red#ILOVEYOU
2. blue#ILOVEYOULALALA
3. green#ILOVEDIANAROSECUSTODIO:)
我想提取红色#或蓝色#或绿色#并将其转移到其他变量。我的手机在每种颜色的末尾发送一个'#',因为我猜它会使提取更容易。
char Comp(char* This){
while(Serial.available() > 0) // Don't read unless
// there you know there is data
{
if(index < 99){
inChar = Serial.read(); // Read a character
if(inChar == '#'){
}
inData[index] = inChar; // Store it
index++; // Increment where to write next
inData[index] = '\0'; // Null terminate the string
}
}
if(strcmp(inData,This) == 0){
for(int i=0;i<19;i++){
inData[i]=0;
}
index=0;
return(0);
}
else{
return(1);
}
}
这是我在arduino中的代码。你看,它在很短的时间内收到一个字符,然后将它添加到一个char数组变量。
答案 0 :(得分:0)
您可以在c。
中使用strtok()函数