<p>I have a char array buffer that I am using to store characters that the user will input one by one.  My code below works but has a few glitches that I can't figure out:</p>

<ol>
<li>when I execute a printf to see what's in Buffer, it does fill up but I get garbage characters at the end</li>
<li>it won't stop at 8 characters despite being declared as char Buffer[8];</li>
</ol>

<p>Can somebody please explain to me what is going on and perhaps how I could fix this? Thanks.</p>

<pre><code>char Buffer[8]; //holds the byte stream
int i=0;

if (/* user input event has occurred */) 
{
        Buffer[i] = charInput;
        i++;

        // Display a response to input
        printf("Buffer is %s!\n", Buffer);

}
</code></pre>

<p>Output:</p>

<pre>
tagBuffer is 1┬┬w!
tagBuffer is 12┬w!
tagBuffer is 123w!
tagBuffer is 1234!
tagBuffer is 12345!
tagBuffer is 123456=!
tagBuffer is 1234567!
tagBuffer is 12345678!</pre>

<p>tagBuffer is 123456789!</p>

You have to end the string with a
```
\0
```
character. That's why they are called zero terminated strings.
It is also wise to allocate 1 extra char to hold the
```
\0
```
.