summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2021-11-18 20:05:12 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2021-11-18 20:05:12 +0800
commitcc22f20114fd0334d30d82550d6082b612abaad5 (patch)
tree8ca378949fb31e89abd7a1a2556a8d924bfafbb5
parentac4f62e049432b5a2b641e12fabbeaab2cc47a6e (diff)
downloadk&r-exercises-cc22f20114fd0334d30d82550d6082b612abaad5.tar.gz
1.14
-rw-r--r--1/14.c26
1 files changed, 26 insertions, 0 deletions
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 <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