/* * Simple word counter... This program should print a horizontal histogram, the * vertical one is a bit harder to make... But hey, let's start simple : -). * * Exercise 1-13 */ #include #define SIZE 10 int main() { int ch, ck, cnt, val, bool; int nword[SIZE]; for ( cnt = 0; cnt < SIZE; ++cnt ) { nword[cnt] = 0; } cnt = val = 0; while ( ( ch = getchar() ) != EOF ) { if ( ch == ' ' || ch == '\n' || ch == '\t' ) { ++nword[val-1]; cnt = 0; } else { val = ++cnt; } } val = cnt = ck = 0; bool = 1; while (bool) { if ( val > nword[cnt] ) { ++ck; } if ( val < nword[cnt] ) { printf("*"); ++cnt; } else { printf(" "); ++cnt; } if ( cnt == SIZE ) { ++val; cnt = 0; printf("\n"); } if ( ck == SIZE ) { bool = 0; } } return 0; }