Program that counts number of occurrence of a letter in a file

Please help me with my program. I need to create a program that asks the user for the filename, then counts the number of occurrence of each letter in that file.

Ex. if the file contains
Absacsac
asdasda

Output will be

a = 6
b = 1
c = 2
.
.
.
z = 0

This has been my program so far:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

#include <cstdlib>



void countingFunction(string sentence)
{
cout<<"Your sentence:"<<sentence<<endl;
int i, j, k, m, l;
int count[25];
int senlength = sentence.length();


for(i=0; i!=senlength; i++)
{
sentence[i] = tolower(sentence[i]);

}




for(i=0; i!=senlength; i++)
{

count[(int)(sentence[i])]++;

}

for(m=97; m<=122; m++)
{

cout<<"\n"<<(char)m<<" = "<<count[m]<<endl;
}

}

int main()
{
string filename;
cout << "What's the file name???? \n" << endl;
cin >> filename;

ifstream inClientFile(filename.c_str(), ios::in);

if(!inClientFile)
{
cerr << "File count could not be opened." << endl;
exit(1);
}

cout<<"Loading successful."<<endl;
string sentence;

while(inClientFile>>sentence)
{

countingFunction(sentence);
}

return 0;
}
Use a counter for each letter. For example, we want to check how many 'A' letter in a sentence? it is simple.

int A_counter // this variable stores how many 'A' letter in a sentence.

The idea is read the entered sentence, then check by using if statement, if if statement finds 'A' letter, our A_counter will increase ( A_counter++ ). In the end, print out A_counter.
yes that was my idea all along but i was thinking that there might be a simpler or shorter way without needing to declare all that acounter, bcounter, ccounter.... etc. Anyway, thanks for your answer man.
Topic archived. No new replies allowed.