aboutsummaryrefslogtreecommitdiffstats
path: root/lcc/tst/cf.c
blob: 28efab784c117b4590a184a753760b81003d9687 (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
27
28
29
30
31
32
/* cf - print character frequencies */
float f[128];

main(argc, argv)
int argc;
char *argv[];
{
	int i, c, nc;
	float cutoff, atof();

	if (argc <= 1)
		cutoff = 0.0;
	else
		cutoff = atof(argv[1])/100;
	for (i = 0; i <= 127; )
		f[i++] = 0.0;
	nc = 0;
	while ((c = getchar()) != -1) {
		f[c] += 1;
		nc++;
	}
	printf("char\tfreq\n");
	for (i = 0; i <= 127; ++i)
		if (f[i] && f[i]/nc >= cutoff) {
			if (i <= ' ')
				printf("%03o", i);
			else
				printf("%c", i);
			printf("\t%.1f\n", 100*f[i]/nc);
		}
	return 0;
}