summaryrefslogtreecommitdiffstats
path: root/1/14.c
diff options
context:
space:
mode:
Diffstat (limited to '1/14.c')
-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