#include #include #include #include int main(int argc, char **argv) { int status; FILE *fp; extern int process(FILE *fp); status = 0; if (argc == 1) { status += process(stdin); } else { for (argv++; --argc > 0; argv++) { if (strcmp(*argv, "-") == 0) { status += process(stdin); } else { if ((fp = fopen(*argv, "r"))) { status += process(fp); fclose(fp); } else { perror(*argv); } } } } exit(status); } int process(FILE *fp) { long freq[256]; int c; for (c = 0; c < 256; c++) freq[c] = 0; while ((c = getc(fp)) != EOF) freq[c]++; for (c = 0; c < 256; c++) { if (freq[c]) { if (isprint(c)) printf("%c: %ld\n", c, freq[c]); else printf("0%o: %ld\n", c, freq[c]); } } return(0); }