Here's my task:
Write a program that asks user to enter name of a file. The program opens the file in binary mode and calculates frequency of all characters [0-255] and prints a list of ten most frequent characters and their frequencies.
Here is most of the code I already wrote:
#pragma warning(disable: 4996)
#include <stdio.h>
int count[26];
int main() {
FILE *f;
int i;
char ch;
char filename[80];
printf("Enter File name\n");
gets(filename);
f = fopen("file.txt", "rb");
while (!feof(f)) {
ch = fgetc(f);
count[ch - 'a']++;
}
for (i = 0; i < 26; i++)
printf("[%c] = %d times\n", 65 + i, count[i]);
fclose(f);
return 0;
}
I'm able to calculate and print the frequency of all characters. How can I print only the ten most frequent?