2014-02-09 252 views
0

我有一个电路,通过蓝牙从我的android程序接受数据(字符数组是特定的)。从字符串中删除字符C

现在,我想要做的是:我的重新编程微控制器,我希望过滤或从我micrcontroller接收阵列提取的字符序列。

我的Android通过这三种字符数组的:

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数组变量中。

+1

你的问题不是很清楚,你的大部分变量都是未声明的。 – ooga

回答

0

您可以在C使用的strtok()函数。

+0

很快! :)谢谢!〜我会在30分钟后发布我的代码。谢谢谢谢,谢谢!〜 – Glenn