Hey guys,
I'm trying to find a way to count all the alphabetic (letters) in a certain text file. Then, convert them to uppercase and display the number of times that letter appears in that text. I'm attaching the text file as it is hard coded.
here is what I have so far:
this unfortunately counts and shows ALL the characters in the text. I'm not sure if there is a function that selects only the letters, but I know I have to us 'toupper()' somewhere.Code:const int LIMIT = 128; ifstream inStream; int lettersArray[LIMIT]; int i; char c; inStream.open("darwin.txt"); if( inStream.fail() ) { cout << "The input file, failed to open. Exiting....\n\n"; exit(-1); } for ( i=0; i<LIMIT; i++ ) { lettersArray[i] = 0; } cout << "The input file contains: \n"; while( inStream >> c) { lettersArray[c]++; } cout << endl; cout << "The non-zero table of values for printable characters are: \n"; for( i=0; i<LIMIT; i++ ) { if( isprint(i) && (lettersArray[i] !=0) ) { cout << (char)i << ":" << lettersArray[i] << ";" ; } cout << endl; } }
any help?
axon



LinkBack URL
About LinkBacks


