title: c++ program to check the frequencies of the letters
body: <p>I am writing a c++ program to check the frequencies of the letters. When the output has no space like &quot;aabbbsssd&quot;, my code can exactly check the frequencies of the letters. However, if the input has space like: &quot;do be do bo.&quot; my output just
  &quot;d 1&quot; and &quot;o 1&quot;, no frequencies of &quot;b&quot; and &quot;e&quot;.</p>
  <h3>Updated code:</h3>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  
  using namespace std;
  
  struct Letters
  {
    Letters() : freq(0){}
    Letters(char letter,int freq) {
      this-&gt;freq = freq;
      this-&gt;letter = letter;
  }
  char letter;
  int freq;
  };
  
  bool Greater(const Letters&amp; a, const Letters&amp; b)
  {
     if(a.freq == b.freq)
        return a.letter &lt; b.letter;
  
     return a.freq &gt; b.freq;
  }
  
  int main () {
  
  cout&lt;&lt;&quot;Enter text:&quot; &lt;&lt; endl;
  string input;
  getline(cin, input);
  
  vector&lt;Letters&gt; count;
  int letters[26]= {0};
  
  for (int x = 0; x &lt; input.length(); x++) {
      if (isalpha(input[x])) {
          int c = tolower(input[x] - 'a');
          letters[c]++;
      }
  }
  
  for (int x = 0; x &lt; 26; x++) {
      if (letters[x] &gt; 0) {
          char c = x + 'a';
          count.push_back(Letters(c, letters[x]));
      }
  }
  
  std::sort(count.begin(),count.end(),Greater);
  
  cout&lt;&lt;&quot;Frequencies:&quot; &lt;&lt; endl;
  for (int x = 0 ; x &lt; count.size(); x++) {
      cout&lt;&lt;count[x].letter &lt;&lt;  &quot; &quot; &lt;&lt; count[x].freq&lt;&lt;&quot;\n&quot;;
    }
  
  
  return 0;
  }
  </code></pre>
  <p>Apologies if this is written poorly, and thanks in advance for the help!</p>