blob: 2b49429daa11e600c9c272152225e3198ec7cb3d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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;
}
|