Cutting up a character array into segments after received in via serial

Hey

Can someone provide a clean and simple way of cutting up my character array buffer into 6 seperate variables of different types?

The incoming char array will look something like this "add 4 25 12 30 0010101 5"

These are the following variables I need to create out of this incoming byte array
add -String variable
4- Byte variable
25 - Byte variables
12- Byte variable
30 Bye variable
0010101 - Byte Array
5 - Byte variable

If it would make it easier the incoming byte array can be changed to have "," separating each part - "add,4,25,12,30,0010101,5"

Thanks in advance for your help.

I think this is what you are looking for

 if (webFile) {
    Serial.print("open rfid file, looking for: ");
    Serial.println(RFIDnum);
    int foundit = 0;
    char myChar;
    // read from the file until there's nothing else in it:
    while (webFile.available()) {
      myChar = webFile.read(); 
      if (myChar == ',') {
        if (RFIDnum == currentLine){foundit = 1;}
      }
      currentLine += myChar;
      if (myChar == '\n') {
        if (foundit) {
           int     commaPosition;  // the position of the next comma in the string
          commaPosition = currentLine.indexOf(',');
          currentLine =currentLine.substring(commaPosition+1, currentLine.length());
          commaPosition = currentLine.indexOf(',');
          myName =currentLine.substring(0,commaPosition);
          currentLine =currentLine.substring(commaPosition+1, currentLine.length());
          commaPosition = currentLine.indexOf(',');
          myCredit =currentLine.substring(0,commaPosition);
          currentLine =currentLine.substring(commaPosition+1, currentLine.length());
          commaPosition = currentLine.indexOf(',');
        
          //Serial.println(myName);
          myNewCredit = 0;
          myNewCredit = StrToFloat(myCredit);
          //Serial.println(myNewCredit);
          foundit = 0;
          
          }
          currentLine = "";

        } 
    }
    // close the file:
    webFile.close();

jasit

Horendus:
Hey

Can someone provide a clean and simple way of cutting up my character array buffer into 6 seperate variables of different types?

Sure: What you want is the strtok_r function (see http://forum.arduino.cc/index.php/topic,41389.0.html).

The delimiter doesn't matter so either a space or a comma would be done the same.

Hope this helps,

Brad
KF7FER

Oh ok, I will have a look at that thread tonight, thanks.

I was thinking of doing something like this for each part which I need from the serialBuffer char array. It should grab the first part of the buffer which is a command name of up to 10 characters in length, stopping at the first "," and copies it to a new array which is then converted into a String which is what I need it to be.

char commandTmp[];

for(byte i =0;i<10;i++){
if((serialBuffer[i])!=(","){
   commandTmp[i] == serialBuffer[i];
}
String command(serialBuffer);

Is there any glaring problems with using this sort of method?

The only thing I would comment on is that you will have 10 empty char in your array before your data