#include #define OUTWORD 0 #define INWORD 1 #define MAXWORDLEN 20 int longest(const int *list) { int max = 0; int length = sizeof list / sizeof *list; for (int i = 0; i < length; i++){ if (list[i] > max) max = list[i]; } return max; } int main () { int c, i, j, wordlen; int ndigit[MAXWORDLEN] = {0}; wordlen = 0; char state = OUTWORD; while ((c = getchar()) != EOF) { if (c == ' ' || c == '\n' || c == '\t') { if (state == INWORD) ++ndigit[wordlen]; wordlen = 0; state = OUTWORD; } else { state = INWORD; ++wordlen; } } int max = longest(&ndigit); // i counts down from the top to the bottom // (actually from a couple above the top, for padding) // we start printing each bar as i gets to be within the bar's value for (i = max + 2; i > 0; i--) { // side axis printf("%2d |", i); for (int j = 0; j < MAXWORDLEN; ++j) printf(" %s ", i <= ndigit[j] ? "=" : " "); printf("\n"); } // bottom axis printf(" +"); for (j = 0; j < MAXWORDLEN; ++j) printf("-|-"); printf("\n |"); for (j = 0; j < MAXWORDLEN; ++j) printf("%3d", j); printf("\n"); }