array initialization discrepancy?

hi all!

i've been trying to initialize a an array of chars, and i've noticed something weird. it seems as if i'm getting an extra character when i initialize the array one way versus another.

i.e.: when i initialize

char serTest[2]={'O','K'};

it's equivalent to this (it's adding the carriage return)

serTest[0]='O'; 
serTest[1]='K'; 
serTest[2]=13;

when i call

Serial.print(serTest);

just me? on purpose? what?

lub,
j

Calling Serial.print with a type of char * expects a null terminated string. Your array is not a normal null terminated string, so the function is traipsing off into memory printing stuff beyond the end of your array until it finds a null.

If you are using it as a string, your array should be initialized as

char serTest[3] = { 'o', 'k', '\0'};

or

char serTest[] = "ok";

These are identical initializations.

-j