#include <stdio.h> #include <ctype.h> /* this code is not pretty, nor does it have to be */ /* run as: bigrams < database | sort -n -r | head -128 will give the 128 most used bigrams in the db. then edit comp.h */ main() { int counts[256][256]; int last; int c; int nhigh = 0; int highest = 0; int lowest = 0; for(c = 0; c < 255; c++) for(last = 0; last < 255; last++) if(!isprint(c) || !isprint(last)) counts[c][last] = -1; else counts[c][last] = 0; while(1) { c = getchar(); if(feof(stdin)) break; if(last == -1 || c == '\n') { if(c != '\n') last = c; continue; } if(counts[last][c] != -1) counts[last][c]++; last = c; } for(c = 0; c < 255; c++) for(last = 0; last < 255; last++) if(counts[c][last] > 0) printf("%d \"%c%c\"\n",counts[c][last],c,last); }