| 1 |
#include <stdio.h> |
|---|
| 2 |
|
|---|
| 3 |
short frequencies[] = { |
|---|
| 4 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|---|
| 5 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|---|
| 6 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|---|
| 7 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|---|
| 8 |
513, 1000, -196, -338, 497, -1420, -1356, -850, 452, -1961, -1513, 726, -2247, -367, 1490, -1300, |
|---|
| 9 |
-158, -2306, -1420, 16, 352, 226, -330, -1495, 0, 959, 1308, 0, 0, 0, 0, 0, |
|---|
| 10 |
0, 1845, 1743, 2658, 234, -4533, -1098, -1782, -1138, 2185, 3159, 4390, -1125, 2217, -2643, 647, |
|---|
| 11 |
297, -4997, -3176, -4854, -505, -1176, 744, -1243, -2163, 3706, 763, 0, 0, 0, 0, 0, |
|---|
| 12 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 628, 0, 0, 0, 363, 0, |
|---|
| 13 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3989, 0, -1279, 513, 4714, 0, |
|---|
| 14 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2405, 0, 0, 0, 0, 0, |
|---|
| 15 |
0, 0, 0, 0, 0, 0, 1777, 0, 0, 0, 6035, 0, 0, 0, 0, 0, |
|---|
| 16 |
-1107, 0, 0, 811, -639, 0, 0, -1107, 725, -745, 0, 0, 0, 0, 1986, 0, |
|---|
| 17 |
0, 0, 0, 0, 0, 0, 0, 0, 888, 0, 0, 0, 0, 0, 725, -1567, |
|---|
| 18 |
-3675, 6477, 2190, 10702, -1107, 0, 0, -2306, -824, -2951, -3262, 0, 5665, 6755, 2178, 1622, |
|---|
| 19 |
0, 0, 811, 1088, -1430, 0, -1567, 0, 4352, 1048, 725, -904, -1107, 3343, 4616, 0, }; |
|---|
| 20 |
|
|---|
| 21 |
int main(int argc, char *argv[]) |
|---|
| 22 |
{ |
|---|
| 23 |
FILE *text = fopen(argv[1],"r"); |
|---|
| 24 |
int frcount = 0; |
|---|
| 25 |
int c; |
|---|
| 26 |
|
|---|
| 27 |
while ((c = fgetc(text)) != EOF) { |
|---|
| 28 |
frcount += frequencies[c]; |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
printf("%s @ %d\n",(frcount>0)?"latin-2":"latin-1",frcount); |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
/* |
|---|
| 35 |
|
|---|
| 36 |
#include <stdio.h> |
|---|
| 37 |
#include <math.h> |
|---|
| 38 |
|
|---|
| 39 |
static unsigned int freq1[256] = {0}, freq2[256] = {0}; |
|---|
| 40 |
static unsigned total1=0, total2=0; |
|---|
| 41 |
|
|---|
| 42 |
static int freqforc(unsigned char i) |
|---|
| 43 |
{ |
|---|
| 44 |
double fr1 = (freq1[i]) / (double)total1, |
|---|
| 45 |
fr2 = (freq2[i]) / (double)total2; |
|---|
| 46 |
|
|---|
| 47 |
double diff = sqrt(fr2) - sqrt(fr1); |
|---|
| 48 |
|
|---|
| 49 |
return diff * 65536. + .5; |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
int main(int argc, char *argv[]) |
|---|
| 53 |
{ |
|---|
| 54 |
FILE *text = fopen(argv[1],"r"); |
|---|
| 55 |
int c, i, j; |
|---|
| 56 |
|
|---|
| 57 |
while ((c = fgetc(text)) != EOF) { |
|---|
| 58 |
if (c >= 0x40) { |
|---|
| 59 |
freq1[c]++; total1++; |
|---|
| 60 |
} |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
fclose(text); |
|---|
| 64 |
|
|---|
| 65 |
text = fopen(argv[2],"r"); |
|---|
| 66 |
|
|---|
| 67 |
while ((c = fgetc(text)) != EOF) { |
|---|
| 68 |
if (c >= 0x40) { |
|---|
| 69 |
freq2[c]++; total2++; |
|---|
| 70 |
} |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
printf("short frequencies[] = {"); |
|---|
| 74 |
|
|---|
| 75 |
for (i = 0; i <= 0xff; i++) { |
|---|
| 76 |
if (!(i & 0xf)) printf("\n"); |
|---|
| 77 |
printf("%d, ",freqforc(i)); |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
printf("};\n"); |
|---|
| 81 |
|
|---|
| 82 |
return 0; |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
*/ |
|---|