Arrays of that wont stay the same size

I’m having problems with the RCM3700, and Dyn. C ver, 9.62.
Specifly, im trying to put 2 characters from one larger array(size 37) into a smaller array(size 2), for the purpose of converting it to a cha, and use it with the RTC. Problem is, the smaller one gets to size 39, and contains the entire string from the 37-size one.

Code:
for (i = 0; i < 2; i++)
{
cocacola[i]=buffer[i];
}
timeyear1=(atoi(cocacola));

Any kind of insight to this would be nice:confused:

You are using the atoi() library function; This function expects a terminator in the argument field. In your example be sure to declare cocacola[] to be 3 chars big and set cocacola[2] = 0; (a nice null terminator). You probably declared both arrays consecutively (char cocacola[2]; char buffer[BUFSIZE]; and when you did a strlen(array_name) you got the results you described.