How to count the number of letters in a text file??

I am writing a program that counts the lines, words and letters in a file, i needed help finding out how I could get the letter counts. This is what I have. anyone help Please!

int main(){
string lineBuffer;
int lineCount=0;
int wordCount=0;
int letterCount=0;
int punctCount=0;
int commaCounter=0;
int peroidCounter=0;
int semiCounter=0;

ifstream outfile(FileName);


if(outfile.is_open()==true){
while(!outfile.eof()){

getline(outfile,lineBuffer);
lineCount++;
cout << lineBuffer <<endl;

for(int i=0; i < lineBuffer.size(); i++){
cout << lineBuffer[i];




getline(outfile,lineBuffer);
switch (lineBuffer[i]){
case',':
commaCounter ++i;
break;
case'.':
peroidCounter ++i;
break;
case';':
semiCounter ++i;
break;
punctCount= commaCounter + peroidCounter + semiCounter;
}

for(int i=0; i<lineBuffer.size(); i++){
wordCount = int (lineBuffer[i]);
wordCount++;
}




}








}
}
cout << lineCount<< endl;
cout << wordCount<<endl;
cout << punctCount<<endl;

outfile.close();
return 0;

}
Why do you need a comma, period and semicolon counter if you have a punctuation counter? You can just add 1 to the punct counter every time you see a punctuation mark.

And for a letter counter, you can run a for loop to count everything that's not a punctuation mark or white space.
oh ok, yea didnt think about it like that. Thanks that should help out alot!
Topic archived. No new replies allowed.