#include <stdio.h>
#include <stdlib.h> // exit()
#include <ctype.h> // isgraph()

void readfreq(FILE *file, int *table) {
    int c = fgetc(file);

    for (; c != EOF; c = fgetc(file))
        table[c]++;
}

int main(int argc, char **argv) {
    int table[256] = { 0 };
    FILE *file = argc == 2 ? fopen(argv[1], "r") : stdin;

    if (!file) perror("Error"), exit(1);

    readfreq(file, table);

    for (int i = 0; i < 256; i++)
        if (table[i] > 0)
            printf(isgraph(i) ? "'%c'  => %d\n"
                              : "0x%02x => %d\n",
                   i, table[i]);

    return 0;
}