title: Creating a dynamic Cstring
body: <p>I am facing this position where I need to create a dynamic string of user-inputted size (so I tried used a dynamic cstring).</p>
  
  <pre><code>char * S;
  int x;
  
  cin &gt;&gt; x;
  
  S = new char[x];
  
  for (int i = 0; i &lt; x; i++) {
      S[i]=' ';        //trying to make it a string of spaces so I can fill it in later
  }
  </code></pre>
  
  <p>upon doing this and outputting the string <code>(cout &lt;&lt; S;)</code> I am getting x spaces and some random characters how do I solve this?</p>