so far i was able to do for countting the letters in a phrase ..,but i am not able to count the words in a phrase and displaying according to the number of the word...here's my code to count the letters.. what changes should i make to count the words in a phrase...here's my code...the output should be like shown at the bottom,.the specific phrase is: whether tis nobler in the mind to suffer
#include <stdio.h>
int main()
{
int phrase;
int aCount = 0;
int bCount = 0;
int eCount = 0;
int hCount = 0;
int iCount = 0;
int nCount = 0;
int oCount = 0;
int qCount = 0;
int rCount = 0;
int sCount = 0;
int tCount = 0;
int uCount = 0;
printf( "Enter the phrase.\n" );
printf( "Enter the EOF character to end input.\n" );
while ( ( phrase = getchar() ) != EOF ) {
switch ( phrase ) {
case 'A':
case 'a':
++aCount;
break;
case 'B':
case 'b':
++bCount;
break;
case 'E':
case 'e':
++eCount;
break;
case 'H':
case 'h':
++hCount;
break;
case 'I':
case 'i':
++iCount;
break;
case 'N':
case 'n':
++nCount;
break;
case 'O':
case 'o':
++oCount;
break;
case 'Q':
case 'q':
++qCount;
break;
case 'R':
case 'r':
++rCount;
break;
case 'S':
case 's':
++sCount;
break;
case 'T':
case 't':
++tCount;
break;
case 'U':
case 'u':
++uCount;
break;
case '\n':
case '\t':
case ' ':
case ',':
case ':':
break;
default:
printf( "Incorrect phrase entered." );
printf( " Enter a new phrase.\n" );
break;
}
}
printf( "\nTotals for phrase are:\n" );
printf( "A: %d\n", aCount );
printf( "B: %d\n", bCount );
printf( "E: %d\n", eCount );
printf( "H: %d\n", hCount );
printf( "I: %d\n", iCount );
printf( "N: %d\n", nCount );
printf( "O: %d\n", oCount );
printf( "Q: %d\n", qCount );
printf( "R: %d\n", rCount );
printf( "S: %d\n", sCount );
printf( "T: %d\n", tCount );
printf( "U: %d\n", uCount );
return 0; /* indicate program ended successfully */
}
/* end function main */
(note: this programs is for specific phrase.)
the output for my program should be like:
if the phrase is : whether tis nobler in the mind to suffer
0 0
1 0
2 2
3 2
4 1
5 1
6 1
7 1
8 0