Outputting spliced version of input
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

int main()
{
  char name[256];
  cout &lt;&lt; "Enter your name: ";
  cin.getline (name,256);

  for(int i = 0; i &lt; 50; i++)
  {  
    cout &lt;&lt; name[i];

    if (name[i] == '\n')
      break;
  }

  cout &lt;&lt; endl;
  return(0);
}
</code></pre>

<p>Enter your name: My name is Sean</p>

<p>once I do that it outputs "My name is Sean" but then a bunch of nonsense crazy symbols after that. </p>

<p>How come it doesn't stop after 'n' in Sean? Since there's a '\n' character there. Or at least I would think. </p>

<p>All, I want is to output every character in name one symbol at a time, and stop when it gets to the end of the line so that it doesn't have to go to 256 when the array is actually much smaller</p>

<p>What's wrong with my code?</p>
