how to do this? write a c++ program that given the name of a text file reads that file and counts the number occurrences of each alphabetic letter in the text. treat upper and lower case instances of a letter as the same letter. hint: look up tolower()---testing the case isn't necessary. if ch is a char, then ch-'a' is a valid c++ expression and will evaluate to 0 when ch is equal to 'a'---try 'b', 'c', and 'd'!)..
really need your help..this is for my case study.
I haven't looked it up nor tried it, but it seems to me with using tolower() you could shorten this to the following:
if ('a' <= tolower(ch) && tolower(ch) <= 'z')
stats[ch - 'a'].count++;
}
tolower(ch) gives the lowercase equivalent of the character if it is uppercase, and returns the input character if it is lowercase. You can look the method up in the C++ reference: http://www.cplusplus.com/reference/clibrary/cctype/tolower/
i tried what you told me Sam but it doesn't output how many letters are there in the text file.. my program goes like this, I will create a text file "108.txt" and I will input letters in it like AabcdE..so when I run the program the output would be 5.it won't output 6 bcoz the program reads 'A' 'a' as one. so instead of 6 letters it is only 5.
how do I count all the letters as one?
instead of
a occured 2 times
b occured 1 times
c occured 1 times
d occured 1 times
e occured 1 times
the output would be like
there are 6 letters in the text file.