2014-02-09 251 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