K&R C Exercise 1-14: Histogram of Character Frequencies

Exercise 1-14. Write a program to print a histogram of the frequencies of different characters in its input. Approach The key insight here is one of the most elegant idioms in C: a character read from getchar() is already an integer — its ASCII value. That value falls in the range 0–127, so it can …

K&R C Exercise 1-13: Histogram of Word Lengths

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. Approach The program breaks into two clear phases: counting word lengths, then rendering the histogram. Counting reuses the IN/OUT state machine …