Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a program to print a histogram of the frequencies of different characters in its input. */
- #include <stdio.h>
- #define ASCII_LIMIT 128
- main() {
- int input;
- int characters[ASCII_LIMIT] = { 0 };
- while ((input = getchar()) != EOF) {
- ++characters[input];
- }
- for (int h = 0; h < ASCII_LIMIT; h++) {
- printf("%c: ", h);
- for (int g = 0; g < characters[h]; g++) {
- printf("x ");
- }
- putchar('\n');
- }
- }
- ######### OUTPUT #########
- bacon is delicious
- ^Z
- :
- :
- :
- :
- :
- :
- :
- :
- :
- :
- : x
- :
- :
- :
- :
- :
- :
- :
- :
- :
- :
- :
- :
- :
- :
- :
- :
- :
- :
- :
- :
- : x x
- !:
- ":
- #:
- $:
- %:
- &:
- ':
- (:
- ):
- *:
- +:
- ,:
- -:
- .:
- /:
- 0:
- 1:
- 2:
- 3:
- 4:
- 5:
- 6:
- 7:
- 8:
- 9:
- ::
- ;:
- <:
- =:
- >:
- ?:
- @:
- A:
- B:
- C:
- D:
- E:
- F:
- G:
- H:
- I:
- J:
- K:
- L:
- M:
- N:
- O:
- P:
- Q:
- R:
- S:
- T:
- U:
- V:
- W:
- X:
- Y:
- Z:
- [:
- \:
- ]:
- ^:
- _:
- `:
- a: x
- b: x
- c: x x
- d: x
- e: x
- f:
- g:
- h:
- i: x x x
- j:
- k:
- l: x
- m:
- n: x
- o: x x
- p:
- q:
- r:
- s: x x
- t:
- u: x
- v:
- w:
- x:
- y:
- z:
- {:
- |:
- }:
- ~:
- :
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement