Question: #include #include #include #define IN 1 #define OUT 0 #define MAX_WORD_LEN 100 int wordbuf[50]; int idx = 0; int words[MAX_WORD_LEN]; void count_words(void) { long nc,

#include #include #include

#define IN 1 #define OUT 0 #define MAX_WORD_LEN 100

int wordbuf[50]; int idx = 0; int words[MAX_WORD_LEN];

void count_words(void) {

long nc, nl, nw; int c, state = OUT; nc = nl = nw = 0; memset(words, 0, sizeof(words));

while ((c = getchar()) != EOF) { ++nc; if (isalpha(c) || c == '-') { wordbuf[idx++] = c; } if (c == ' ') { ++nl; } if (isspace(c)) { state = OUT; } else if (state == OUT) { state = IN; if (nw > 0) { add_word(); } ++nw; } } if (idx > 0) { idx++; add_word(); } printf("%ld chars, %ld words, and %ld lines ", nc, nw, nl); }

void add_word(void) { }

void print_horiz_histogram(void) { printf(" "); for (int i = 1; i < MAX_WORD_LEN; i++) { printf("%2d | ", i); for (int j = 0; j < words[i]; j++) printf("*"); printf(" "); } }

void print_vert_histogram(void) { for (int i = idx; i >= 1; i--) { for (int j = 1; j <= MAX_WORD_LEN; j++) { if (words[j] > i) { printf(" *"); } else { printf(" "); } } printf(" "); } /* Draws a verticle line */ for (int j = 1; j <= MAX_WORD_LEN; j++) { printf("---"); } printf(" "); /* Print the counts */ for (int j = 1; j <= MAX_WORD_LEN; j++) { printf("%3d", j); } printf(" "); }

int main(int argc, const char* argv[]) { count_words(); print_horiz_histogram(); print_vert_histogram(); }

please edit add_word function to be able to print out the vertical and horizontal historgram

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!