Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Real Time Database And Information Systems Research Advances

Authors: Azer Bestavros ,Victor Fay-Wolfe

1st Edition

1461377803, 978-1461377801

More Books

Students also viewed these Databases questions