New to C++, need help. Sending Multiple Values in String

I'm using the meetAndroid lib, and from my phone I'm sending this string "9,9,100,100,100"
I'm trying to get it to output :
X = 9
Y = 9
R = 100
G = 100
B = 100

But when it outputs it says this:
X = 9109
Y = 9
R = 100100100????
G = 100100????
B = 100????

void stringValue(byte flag, byte numOfValues)
  int length = meetAndroid.stringLength();
  char data[length];
  char X[3];
  char Y[3];
  char R[3];
  char G[3];
  char B[3];

  int change = 0;
  int in = 0;
  for (int i=0; i<length-1; i++)
	if(data[i] == ',')
		meetAndroid.send(", Detected");
		in = 0;
		switch (change) {
			case 0:
				X[in] = data[i];
				meetAndroid.send("Processed 0 (x)");
			case 1:
				Y[in] = data[i];
				meetAndroid.send("Processed 1 (y)");
			case 2:
				R[in] = data[i];
				meetAndroid.send("Processed 2 (r)");
			case 3:
				G[in] = data[i];
				meetAndroid.send("Processed 3 (g)");
			case 4:
				B[in] = data[i];
				meetAndroid.send("Processed 4 (b)");

Does anyone see what I did wrong, it looks like it should work, but its not.

It looks like you are having a problem with not terminating strings. Strings (when using char[] ) need a zero byte at the end to be correctly terminated. Your code looks like it tries to store a three character string in a three-byte array, which doesn't leave enough room for the 0 at the end. Also your code doesn't look like it writes the 0 byte at the end of each string. I suspect that's why the output looks like the strings are running into each other.

How would I write the zero byte at the end?

'\0' is the null character string constant.

or you can create a null character

char_array[ max ] = char(0);

How would I write the zero byte at the end?

after this
X[in] = data[i ];
add this

And similar for all the others.

it doesn't need to be at the end of the array. where ever you put the null character will determine the length of your string.

char c_Str[ 27 ];

char a = 'a';

//fill with alphabet
for( int i = 0 ; i < 26 ; ++i ){

  c_Str[ i ] = a + i;
c_Str[ 26 ] = '\0'; //places null at end. { abcdefghijklmnopqrstuvwxyz\0 }

c_Str[ 13 ] = '\0'; //places null at half. { abcdefghijklm\0opqrstuvwxyz\0 } contains 27 elements but 13 are the string { abcdefghijklm\0 }

your X variable needs room for the null, if you need 3 chars for '100' create 4.

if you set the entire contents of the array to '\0' and only write to the first 3 chars, you will have a null terminated char array.

  int length = meetAndroid.stringLength();
  char data[length];

This is not the proper way to dynamically allocate an array. First, the array is not large enough to hold the trailing NULL that must be present.

Second, you should be using malloc() to allocate the space, and free() to free it when you are done.

Some simple code that might be close to what you are looking for. Put your 9,9,100,100,100 string in the serial monitor (you can copy, then use ctrl-v to paste it), send it to the arduino, and see if it returns broken into the parts you want.

//zoomkat 11-8-11 simple delimited ',' string parce 
//from serial port input (via serial monitor)
//and print result out serial port
// CR/LF could also be a delimiter

String readString;

void setup() {
  Serial.println("serial delimit test 0022"); // so I can keep track of what is loaded

void loop() {

  //expect a string like wer,qwe rty,123 456,hyre kjhg,
  //or like hello world,who are you?,bye!,
  while (Serial.available()) {
    delay(1);  //small delay to allow input buffer to fill
    char c =;  //gets one byte from serial buffer
    if (c == ',') {
      break; //breaks out of capture loop to print readstring
    readString += c; //makes the string readString

  if (readString.length() >0) {
    Serial.println(readString); //prints string to serial port out

    readString=""; //clears variable for new input