title: counting characters in char array
body: <p>i wrote following code to count occurance of characters in given char array</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  int main(){
  
  char f[]={'a','a','b','c','c','d','d','f','e','e'};
  int n=sizeof(f)/sizeof(char);
  char max=f[0];
  for (int i=1;i&lt;n;i++)
  {
      if(f[i]&gt;max)
      {
          max=f[i];
      }
  }
  
  int m=(int)(max)+1;
  int  *b=new int [m];
  
  for (int i=0;i&lt;n;i++)
  {
      b[(int)(f[i])]++;
  }
  
  for (int i=0;i&lt;m;i++)
  {
      if(b[i]!=0)
      {
      cout&lt;&lt;(char)(i)&lt;&lt;" occurs  "&lt;&lt;b[i]&lt;&lt; "times "&lt;&lt;endl;   
      }      
  }
  
  return 0;
  }
  </code></pre>
  
  <p>but it shows very bad result</p>
  
  <pre><code> occurs  -842150451times
  ☺ occurs  -842150451times
  ☻ occurs  -842150451times
  ♥ occurs  -842150451times
  ♦ occurs  -842150451times
  ♣ occurs  -842150451times
  ♠ occurs  -842150451times
   occurs  -842150451times
   occurs  -842150451times
           occurs  -84215045
  
   occurs  -842150451times
  ♂ occurs  -842150451times
  ♀ occurs  -842150451times
   occurs  -842150451times
  ♫ occurs  -842150451times
  ☼ occurs  -842150451times
  ► occurs  -842150451times
  ◄ occurs  -842150451times
  ↕ occurs  -842150451times
  ‼ occurs  -842150451times
  ¶ occurs  -842150451times
  § occurs  -842150451times
  ▬ occurs  -842150451times
  ↨ occurs  -842150451times
  ↑ occurs  -842150451times
  ↓ occurs  -842150451times
  → occurs  -842150451times
  ← occurs  -842150451times
  ∟ occurs  -842150451times
  ↔ occurs  -842150451times
  ▲ occurs  -842150451times
  ▼ occurs  -842150451times
    occurs  -842150451times
  ! occurs  -842150451times
  " occurs  -842150451times
  # occurs  -842150451times
  $ occurs  -842150451times
  % occurs  -842150451times
  &amp; occurs  -842150451times
  ' occurs  -842150451times
  ( occurs  -842150451times
  ) occurs  -842150451times
  * occurs  -842150451times
  + occurs  -842150451times
  , occurs  -842150451times
  - occurs  -842150451times
  . occurs  -842150451times
  / occurs  -842150451times
  0 occurs  -842150451times
  1 occurs  -842150451times
  2 occurs  -842150451times
  3 occurs  -842150451times
  4 occurs  -842150451times
  5 occurs  -842150451times
  6 occurs  -842150451times
  7 occurs  -842150451times
  8 occurs  -842150451times
  9 occurs  -842150451times
  : occurs  -842150451times
  ; occurs  -842150451times
  &lt; occurs  -842150451times
  = occurs  -842150451times
  &gt; occurs  -842150451times
  ? occurs  -842150451times
  @ occurs  -842150451times
  A occurs  -842150451times
  B occurs  -842150451times
  C occurs  -842150451times
  D occurs  -842150451times
  E occurs  -842150451times
  F occurs  -842150451times
  G occurs  -842150451times
  H occurs  -842150451times
  I occurs  -842150451times
  J occurs  -842150451times
  K occurs  -842150451times
  L occurs  -842150451times
  M occurs  -842150451times
  N occurs  -842150451times
  O occurs  -842150451times
  P occurs  -842150451times
  Q occurs  -842150451times
  R occurs  -842150451times
  S occurs  -842150451times
  T occurs  -842150451times
  U occurs  -842150451times
  V occurs  -842150451times
  W occurs  -842150451times
  X occurs  -842150451times
  Y occurs  -842150451times
  Z occurs  -842150451times
  [ occurs  -842150451times
  \ occurs  -842150451times
  ] occurs  -842150451times
  ^ occurs  -842150451times
  _ occurs  -842150451times
  ` occurs  -842150451times
  a occurs  -842150449times
  b occurs  -842150450times
  c occurs  -842150449times
  d occurs  -842150449times
  e occurs  -842150449times
  f occurs  -842150450times
  </code></pre>
  
  <p>please help me what is wrong?</p>