From cc22f20114fd0334d30d82550d6082b612abaad5 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Thu, 18 Nov 2021 20:05:12 +0800 Subject: 1.14 --- 1/14.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 1/14.c (limited to '1/14.c') diff --git a/1/14.c b/1/14.c new file mode 100644 index 0000000..2b49429 --- /dev/null +++ b/1/14.c @@ -0,0 +1,26 @@ +#include + +// 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 -- cgit v1.2.3