#include <iostream>
#include <fstream>
#include <cctype>
using std::fstream;
using namespace std;
int count[26];
int main(int argc, char *argv[])
{
char ch;
ifstream infile("c:\\a.txt") ;
if ( !infile )
{
cerr << "File could not be opened" << endl;
exit( 1 );
}
int i;
for(i = 0; i <26; i++) count[ i ] = 0;
while (! infile.eof())
{
ch = cin.get();
if(isalpha(ch))
{
ch = toupper(ch);
count[ch-'A']++;
}
};
for(i = 0; i <26; i++) {
cout << (char) ('A'+ i) << ": " << count[ i ] << '\n';
}
return 0;
}
what i wanted to do with this code was input a stream of alphabetical characters and output the amount of each alphabetical letter. for ex. if the text said aaabbccccc.....yyzzzz i want to output
a:3
b:2
c:5 etc etc
but even this compiles alrigght and file was opened all i get is a blank screen. i'm really stumped and since i'm such a newbie i really don't know what im doing wrong. ang suggestions or comments will be useful.