5 int main(int argc
, char *argv
[])
8 * When we partially initialize an array,
9 * C automatically initializes the rest of it
10 * to 0, NULL, etc, depending on the element type
12 * That said, the following is adequate:
14 unsigned int freq
[26] = { 0 }; /* Frequencies for 'A' to 'Z' */
15 unsigned int i
, j
, maxf
;
19 /* check argument count */
21 fprintf(stderr
, "usage: %s path\n", argv
[0]);
25 /* open file for reading */
26 if ((fp
= fopen(argv
[1], "r")) == NULL
) {
31 /* count frequencies */
32 while ((c
= fgetc(fp
)) != EOF
) {
34 if (c
>= 'A' && c
<= 'Z')
38 /* get max frequency */
40 for (i
= 1; i
< sizeof freq
/ sizeof *freq
; i
++)
44 /* print frequencies */
46 for (i
= freq
[maxf
]; i
> 0; i
--) {
48 for (j
= 0; j
< sizeof freq
/ sizeof *freq
; j
++)
58 for (i
= 0; i
< sizeof freq
/ sizeof *freq
; i
++)
59 printf("%c", (char)('A' + i
));
65 * (since we opened the file only for read,
66 * we assume that it is safe to not check against
67 * the return value of fclose())