Problem with color sensor

Hi all , i am having trouble with making this color sensor work. I dont know what i have done wrong in my code but i am not able to get it to work.

This is the code i am using:

char color[19];

void setup(){
  Serial.begin(9600);
  Serial.write("Ready");
  Serial.println();
  delay(100);
}

void loop(){
  if(Serial.available() != 0){
    for(int x=1; x<18; x++){
      color[x] = Serial.read();
      if(color[18] == 0x0A){
        Calibrate();
      }
    }
  }
}

void Calibrate(){
  int R;
  int G;
  int B;
  
  R = (((color[3]-'0')*100) + ((color[4]-'0')*10) + (color[5]-'0'));
  G = (((color[9]-'0')*100) + ((color[10]-'0')*10) + (color[11]-'0'));
  B = (((color[15]-'0')*100) + ((color[16]-'0')*10) + (color[17]-'0'));
  
  Serial.println(R);
  Serial.println(G);
  Serial.println(B);
  Serial.println();
}

And this is the datasheet of the sensor: http://www.sunrom.com/files/1185-datasheet.pdf

I need advice and help on how to get this working fast.
Thx in advance.

Amruth

Usual problem - check to see if there's at least one character available to read, then go ahead and read all 18 of them.
Also, array indices usually begin at zero.

. I dont know what i have done wrong in my code but i am not able to get it to work.

You need to define what "work" means to you in this context.

i get my readings but they are all gibberish, i have set baud rates correctly but still the readings are in negative and above 1000.

i get my readings but they are all gibberish

No, there're mostly -1.
Re-read reply #1

Not able to figure out anything =(

Look at your code
Is there a single character in the serial receive buffer?
Yes, so read all eighteen of them.

Does that seem like a sensible thing to do?

Some useful reading:

Hint: you're not the first person to make this mistake.

AWOL:
Usual problem - check to see if there's at least one character available to read, then go ahead and read all 18 of them.

I agree that is a problem with the code as posted.

AWOL:
Also, array indices usually begin at zero.

They do, but oddly, part of the code (the read loop) is 1-based while another part (the parsing) is correctly 0-based. As an example, the first bit of actual information is the fourth character, "Red Value Hundreds Character ASCII" and the code correctly accesses this fourth item as

(color[3]-'0')*100)

help on how to get this working fast.

At 9600 it is never going to be particularly fast.