Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Exercise 1-13. Write a program to print a histogram of the lengths of words in its input. It is easy to draw the histogram with
Exercise 1-13. Write a program to print a histogram of the lengths of words in its input. It is easy to draw the histogram with the bars horizontal; a vertical orientation is more challenging.
that is the sample output they want us to set up
//----------------------------------------------------------- void count_words(void) { // pre-C99 -- have to write void if no args 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(); } // don't add entering the first word ++nw; } } if (idx > 0) { // words just before the EOF with no leading whitespace ++idx; add_word(); } printf("%ld chars, %ld words, and %ld lines ", nc, nw, nl); } //----------------------------------------------------------- //----------------------------------------------------------- int main(int argc, const char * argv[]) { // count lines, words, and chars in input count_words(); print_horiz_histogram(); print_vert_histogram(); return 0; }adding word. 'like' adding word. 'that' 1473 chars. 261 words wax 15:16 and 6 lines 1 * * * 4: EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 6: Saada saada 1: 2: 3: 4: 5: 6: 7: 8: 9:18: 11: 12:13: 14: 15: 16:17: 18:19: 20:21: 22:23: 24
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started