user31546: I'm trying to convert a char array to a char. i used this code
char code[4] = {'1','2','3','4'};

char strcode[4];



void setup()
{
    Serial.begin(9600);
}


void loop()
{
    memcpy(strcode, code, 4);
    Serial.println(strcode);
    Serial.println("done");
    delay(1000);
}

But for some reason when i read my serial monitor i get this:
1234
done

Why are there 2 squares behind it?  Am I doing it wrong?
EDIT: For some reason stackexchange doesn't show the 2 squares but there are 2 squares behind 1234

user368: C strings need to be NUL-terminated.
char strcode[5];

 ...

 ...
     ...
    strcode[4] = '\0';
     ...


31546: <p>I'm trying to convert a char array to a char. i used this code</p>

<pre><code>char code[4] = {'1','2','3','4'};

char strcode[4];



void setup()
{
    Serial.begin(9600);
}


void loop()
{
    memcpy(strcode, code, 4);
    Serial.println(strcode);
    Serial.println("done");
    delay(1000);
}
</code></pre>

<p>But for some reason when i read my serial monitor i get this:</p>

<pre><code>1234
done
</code></pre>

<p>Why are there 2 squares behind it?  Am I doing it wrong?</p>

<p>EDIT: For some reason stackexchange doesn't show the 2 squares but there are 2 squares behind 1234</p>
 368: <p>C strings need to be NUL-terminated.</p>

<pre><code>char strcode[5];

 ...

 ...
     ...
    strcode[4] = '\0';
     ...
</code></pre>
