(SOLVED)Can any one help?

Ok i have better results now with strings under 16 bytes long but still can't work out what is going on when i type 1234567891234567> in the serial monitor. The sketch reboots with the code below. I thought that if i gets to 16 then the function is meant to exit with that if statment. Can you tell me what is going wrong? Am i correct in thinking that the last number in the string is placed into buffer location 16> Thank you.

//Reads data from the ELM IC.
//For example 41 0C 7B 7B>.
byte STN_Read(char *str)
{
  byte i = 0;
  char temp;
  
  while((temp = Serial.read()) != '>')
  {
    if(temp >= ' ' && temp <= '~')
    {
      str[i++] = temp;
      str[i] = '\0';
    }
    if(i == 16)
    {
      return 0;
    }
  }
  return 1; //Read is probably good.
}