#include #include char* char_names[] = { "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel", "bs ", "ht ", "nl ", "vt ", "np ", "cr ", "so ", "si ", "dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb", "can", "em ", "sub", "esc", "fs ", "gs ", "rs ", "us ", "sp ", " ! ", " \" ", " # ", " $ ", " % ", " & ", " ' ", " ( ", " ) ", " * ", " + ", " , ", " - ", " . ", " / ", " 0 ", " 1 ", " 2 ", " 3 ", " 4 ", " 5 ", " 6 ", " 7 ", " 8 ", " 9 ", " : ", " ; ", " < ", " = ", " > ", " ? ", " @ ", " A ", " B ", " C ", " D ", " E ", " F ", " G ", " H ", " I ", " J ", " K ", " L ", " M ", " N ", " O ", " P ", " Q ", " R ", " S ", " T ", " U ", " V ", " W ", " X ", " Y ", " Z ", " [ ", " \\ ", " ] ", " ^ ", " _ ", " ` ", " a ", " b ", " c ", " d ", " e ", " f ", " g ", " h ", " i ", " j ", " k ", " l ", " m ", " n ", " o ", " p ", " q ", " r ", " s ", " t ", " u ", " v ", " w ", " x ", " y ", " z ", " { ", " | ", " } ", " ~ ", "del" }; int bit8; void take_hist(FILE* fp, long* counter) { int c; if(bit8) while((c = getc(fp)) != EOF) counter[c]++; else while((c = getc(fp)) != EOF) if(c <= 127) counter[c]++; else counter[128]++; } int main(int argc, char** argv) { static long char_cnt[256]; int i; if(argc >= 2 && !strcmp(argv[1], "-8")) { bit8 = 1; i = 2; } else { bit8 = 0; i = 1; } if(i == argc) take_hist(stdin, char_cnt); else { FILE* fp; for(; i < argc; i++) { if((fp = fopen(argv[i], "r")) == NULL) { perror("argv[i]"); continue; } take_hist(fp, char_cnt); fclose(fp); } } for(i = 0; i <= 127; i++) printf("%ld\t%s\n", char_cnt[i], char_names[i]); if(bit8) for(; i < 256; i++) printf("%ld\t%03o\n", char_cnt[i], i); else printf("%ld\t128..255\n", char_cnt[i]); return 0; }