Pavilion1984:
str[i++] = temp;
This code to increment the character index executes every time a character is received, regardless of whether the buffer is already full. I suggest you add a check along these lines:
if(i < MAXLEN)
{
str[i++] = temp;
str[i] = 0;
}
Note that the size of the array needs to be MAXLEN+1 to include space for the null terminator. You could declare it like this:
const int MAXLEN=16;
char str[MAXLEN+1];