I'm trying to write a program to count the number of each letter of the alphabet and count the words. I have the word count but don't know how to start my letter counts.
thanks in advance for your help...
Here is what i have so far:
# include <iostream.h>
# include "string.h"
void alphabet( char [] ); //functions prototype
int main()
{
int count = 0;
char string[256];
cout <<"Please enter 1 line of text from the keyboard. \n";
cout <<"Please hit enter when you are done.\n\n";
cin.getline(string, 256, '\n'); //The user input goes into string
int countA = 0;
for(int i = 0; i < 256; i++)
{
if (string[i] == 'a' || 'A')
countA++;
else
}
cout <<"A " << countA << "\n";
char *tokenPtr;
tokenPtr = strtok( string, " " );
while ( tokenPtr != NULL )/* The following code counts the words or tokens in a sentence.*/
{
tokenPtr = strtok( NULL, " " );
count = count + 1;
}//end while ( tokenPtr != NULL )
cout << "Word Count: " << count;
return 0;
}//end int main ()



LinkBack URL
About LinkBacks


