diff options
| -rw-r--r-- | 1/14.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -0,0 +1,26 @@ +#include <stdio.h> + +// printable ascii extended charset +#define MAXCHAR 95 +#define FCHAR ' ' + +/* prints a histogram of frequencies of different characters in input */ +int main(int argc, char *argv[]) { + int i, j, c; + int freq[MAXCHAR]; + + for (i = 0; i < MAXCHAR; i++) + freq[i] = 0; + + while ((c = getchar()) != EOF) + freq[c - FCHAR]++; + + for (i = 0; i < MAXCHAR; i++) { + printf("%c: ", i + FCHAR); + for (j = 0; j < freq[i]; j++) + putchar('x'); + putchar('\n'); + } + + return 0; +}
\ No newline at end of file |
