/* * Пример программы обработки файла статистики для эмулятора PDPC. * Печать "Top 100 opcodes". * (c) Полетаев В.М. */ #include #include #define size 100 /* число выводимых счетчиков */ char name[] = "pdpcstat.dat"; main() { FILE *f; unsigned int cop; unsigned long cnt; unsigned long *cntptr; unsigned int *copptr; int i,j; if ((f = fopen(name,"rb")) == 0) { fprintf(stderr, "Not found %s\n", name); return 4; } if ( ((cntptr = calloc(sizeof cnt, size)) == 0) || ((copptr = calloc(sizeof cop, size)) == 0) ) { fprintf(stderr, "Insufficient memory\n", name); return 4; } cop = 0; do { fread(&cnt, sizeof cnt, 1, f); for (i = 0; i < size; i++) if (cnt > cntptr[i]) { for (j = size-1; j > i; --j) { cntptr[j] = cntptr[j-1]; copptr[j] = copptr[j-1]; } cntptr[i] = cnt; copptr[i] = cop; break; } } while (++cop != 0); for (i = 0; i < size; i++) printf("%06o %lu\n", copptr[i], cntptr[i] ); return 0; }