serial.read problem

I have 2 Arduino’s communicating through Xbee. On the first one I have the following code:

void setup()
{
  Serial.begin(9600);
}
void loop()
{
     Serial.print (millis()/100);
    delay(1000);
    }

On the serial monitor I get a line of 0102030…alright.
If on the second microcontroler I write:

char    buffer[3];
int val;
void setup()
{
  Serial.begin(9600);
}
void loop()
{
if ( Serial.available() > 0 )
{
    buffer[0] = Serial.read();
    buffer[1] = Serial.read();
    buffer[2] = Serial.read();

    int     n;
    n = atoi(buffer);
    Serial.println(n);
}
}

Then I get a column of
0
1
0
2
0
.
.
and I don’t know how to use this in a Processing code?
What should I use to get again as output of the second Arduino the same line of 0102030… I had with the first one?
Maybe atoi() is not a good idea?
Any help?

check 'available' before 'read'

check 'available' before 'read'

Correct. The OP needs to understand that a single available check statement (returning > 0) does not mean there are three characters ready, but he then reads them all in a row as if they were avalible.

Either check for available == 3 or do an available check before doing each character read.

Lefty

You must also NULL terminate the array (buffer) before calling any string function, like atoi, with that array as an argument. Results will not be what you expect if you do not.