OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [lcc/] [tst/] [cf.c] - Blame information for rev 149

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 hellwig
/* cf - print character frequencies */
2
float f[128];
3
 
4
main(argc, argv)
5
int argc;
6
char *argv[];
7
{
8
        int i, c, nc;
9
        float cutoff, atof();
10
 
11
        if (argc <= 1)
12
                cutoff = 0.0;
13
        else
14
                cutoff = atof(argv[1])/100;
15
        for (i = 0; i <= 127; )
16
                f[i++] = 0.0;
17
        nc = 0;
18
        while ((c = getchar()) != -1) {
19
                f[c] += 1;
20
                nc++;
21
        }
22
        printf("char\tfreq\n");
23
        for (i = 0; i <= 127; ++i)
24
                if (f[i] && f[i]/nc >= cutoff) {
25
                        if (i <= ' ')
26
                                printf("%03o", i);
27
                        else
28
                                printf("%c", i);
29
                        printf("\t%.1f\n", 100*f[i]/nc);
30
                }
31
        return 0;
32
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.