title: How to check how many times the letters of the alphabet occur in a text file C++
body: <p>I want to check how many times the letters of the alphabet are in a text file. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  #include &lt;cctype&gt;
  
  using namespace std;
  
  
  int main()
  {
  char alphabet[]="abcdefghijklmnopqrstuvwxyz";
  //char alphabet[26]= {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  int letter_c[26]; //will contain the times each letter is repeated
  string line;
  
  //get text file
  ifstream myfile ("hi.txt");
  
  //if file opens...
    if (myfile.is_open())
    {
       while ( getline (myfile,line) )
       {  
           cout &lt;&lt; line &lt;&lt; '\n';
  
            //lowercase everything
            for (int i = 0; i &lt; line.length(); i++)
            {
                line[i] = tolower(line[i]);
            }  
  
            //check if letter ? is in that text file and how many times
            for (int i = 0; i &lt; line.length(); i++)
            {
                 int count=0;
                 for(int j=0; j&lt;strlen(alphabet);i++)
                 {
                     if(line[i]==alphabet[j])
                     {
                        cout&lt;&lt;"letter: alphabet "&lt;&lt;alphabet[j]&lt;&lt;endl;
                        cout&lt;&lt;"letter: text "&lt;&lt;line[i]&lt;&lt;endl;
                        letter_c[i]=count++;
                        //cout&lt;&lt;count&lt;&lt;endl;
                      }
                 cout&lt;&lt;alphabet[i]&lt;&lt;" "&lt;&lt;letter_c[i]&lt;&lt;endl;
             }
        }
   }
  
  //close file
  myfile.close();
    }
  
    //file not found
    else cout &lt;&lt; "Unable to open file"; 
  
  return 0;
  
  }
  </code></pre>
  
  <p>I believe this if statement is what is messing up my code:</p>
  
  <pre><code>if(line[i]==alphabet[j])
  {
  cout&lt;&lt;"letter: alphabet "&lt;&lt;alphabet[j]&lt;&lt;endl;
  cout&lt;&lt;"letter: text "&lt;&lt;line[i]&lt;&lt;endl;
  letter_c[i]=count++;
  //cout&lt;&lt;count&lt;&lt;endl;
  }
  </code></pre>
  
  <p>I have tried using  line[i].compare(alphabet[j]) == 0
  and I have also tried strcmp (line[i],alphabet[j]) == 0
  and neither of them work.</p>