Design a word and character counter and display a histogram of particular characters.
The histogram may use any character to denote a single instance of a particular letter, such as an X, and should print the number of instances for that letter at the end of the line. Only print the results for characters that have one or more occurrences in the entered sentence. Your program must treat lower case and upper case of the same letter as separate characters.
Below is an example of what a histogram might look like for the sentence: i Looooove eps II
Word total: 4
Character total: 18
e: XX (2)
i: X (1)
o: XXXXX (5)
p: X (1)
s: X (1)
v: X (1)
I: XX (2)
L: X (1)
My problem is that when I compile and test the program, only a histogram for the first word of the sentence is printed to the screen, I dont know if entering a space is stopping the rest of the program from completing? Here is the code I have for the histogram function.
void histogram(char array3[]){
int counts[256] = {0};
int num_words = 0;
int num_chars = 0;
int num_underscores = 0;
int in_word = 0;
int i,x,j;
for( i = 0; array3[i] != 0; i++ ){
if( isalpha(array3[i]) ){
counts[array3[i]]++;
num_chars++;
}
}
for(i = 0; i < 256; i++ ){
if( counts[i] == 0 ) continue;
printf( "%c: ", (char)i );
for(x = 0; x < counts[i]; x++ ) fputc('X', stdout);
printf("(%d)\n", counts[i] );
}
}