title: The Program gives garbage value for name[i], i= 1 to 3
body: <p>I am a beginner to programming. I was building a program to read in a single string, store it in different arrays and print them. But the output gives garbage values for <code>name[0]</code> and <code>name[1]</code> but the correct values for <code>name[2]</code> and <code>name[3]</code>. Any idea?</p>
  
  <pre><code>char buffer[80];
  cin.getline(buffer, 80, '$');   
  char* name[4];
  name[0] = buffer;
  int count = 0;  
  for (char* p = buffer; *p != '\0'; p++)
      if (*p == '\n') {
          *p = '\0';  
          name[++count] = p+1;
      }
  cout &lt;&lt; " Your Enteries are :" &lt;&lt; '\n'; 
  for (int i = 0; i &lt; count; i++)
      cout &lt;&lt; '\t' &lt;&lt; i &lt;&lt; ". [" &lt;&lt; name[i] &lt;&lt; "] " &lt;&lt; endl;
  </code></pre>