title: Using char*array to store a bar for a bar graph so I can dynamically make it and return as a string
body: <p>What my program does is it reads in a file char by char counting digits and letters only it then prints the data to the screen, with it labeled what particular digit or letter, that particular letters count, and then a bar representation of it.
  I have already made an implementation of this that works with an empty string, using a for loop to append "=" on the string to form a bar. What I want to do with it instead is use a char* to dynamically create an char[] of x size. I use the following method to do so </p>
  
  <pre><code>//typedef casting
   typedef int index;
   typedef int char_count;
   typedef int index_constant;
   typedef int number_of_chars;
   typedef char next_char;
   typedef string bar;
   typedef string label;
   typedef string file;
   typedef string message;
  
       const bar build_bar(char_count x)
       {
             bar bar ="";
             char *bar_Holder = new char[x];
             for (size_t i = 0; i &lt; x; i++)
             {
                  bar_Holder[i] = '=';
             }
             bar = bar_Holder;
             delete[] bar_Holder;
             return bar;
       }
  </code></pre>
  
  <p>Then I print the graph to the screen using this method:</p>
  
  <pre><code>void print(digits_letters_counter x, int spacing)
  {
      index j = 0;
      for (index i = 0; i &lt; number_of_chars_counted; i++, j++)
      {
          if (i &lt; 10) 
          {
              i = i + digit_index_range;
              cout &lt;&lt; (char)i &lt;&lt; ":" &lt;&lt; setw(spacing) &lt;&lt;setfill(' ')&lt;&lt; build_label(x.digit_letter_counter[j])&lt;&lt; build_bar(x.digit_letter_counter[j]) &lt;&lt; endl;
              i = i - digit_index_range;
          }
          else if (i &gt;= 10) 
          {
              i = i + alpha_index_range;
              cout &lt;&lt; (char)i &lt;&lt; ":" &lt;&lt; setw(spacing) &lt;&lt; setfill(' ') &lt;&lt; build_label(x.digit_letter_counter[j]) &lt;&lt; build_bar(x.digit_letter_counter[j]) &lt;&lt; endl;
              i = i - alpha_index_range;
          }
      }
  }  
  </code></pre>
  
  <p>When i run this code I will get an out put like this which will have the appropriate number of bars but will have junk data tagged onto the end of it.</p>
  
  <blockquote>
    <p>Enter the file name to be counted: sample.txt 0:3===²²²² 1:1=²²²²▌▌
    2:4====²²²²Q 3:4====²²²²Q 4:2==²²²²▌▌Q 5:2==²²²²▌▌Q 6:4====²²²²Q
    7:0²²²²▌▌▌▌Q 8:0²²²²▌▌▌▌Q 9:2==²²²²▌▌Q A:5=====²²²²▌▌▌▌▌▌▌v▌
    B:1=²²²²▌▌▌Q C:0²²²²▌▌▌▌Q D:3===²²²²▌Q E:5=====²²²²▌▌▌▌▌▌▌RÇ▌
    F:4====²²²²Q G:0²²²²▌▌▌▌Q
    H:41=========================================²²²²y
    I:5=====²²²²▌▌▌▌▌▌▌v▌ J:0²²²²▌▌▌▌Q K:1=²²²²▌▌▌Q L:4====²²²²Q
    M:2==²²²²▌▌Q N:5=====²²²²▌▌▌▌▌▌▌┬0▌ O:4====²²²²Q P:1=²²²²▌▌▌Q
    Q:0²²²²▌▌▌▌Q R:0²²²²▌▌▌▌Q S:9=========²²²²▌▌▌.▌ T:4====²²²²Q
    U:0²²²²▌▌▌▌Q V:2==²²²²▌▌Q W:0²²²²▌▌▌▌Q X:1=²²²²▌▌▌Q Y:0²²²²▌▌▌▌Q
    Z:0²²²²▌▌▌▌Q Press any key to continue . . .
    My question is how do I get rid of the junk data or even prevent it from be allocated and stored like this?</p>
  </blockquote>