I have next challenge and need a little help ;)
Program to write: The file is treated as a row of 8-bit symbols.
- Count the frequency (incidence) of these symbols
- Count the frequency of these symbols after symbols (if the previous character is given, in front of first charakter is sign with code 0).
The program should work for doc, pdf, mp4, jpg (take a min 1MB file).
So I wrote a little bit of code; here it is:
main:
int array[256] = {0};
double charArray[256][256] = {{0}};
FILE *fp = fopen("test.txt", "rb");
int c;
int b = 0;
printf("File content: \n");
while((c = fgetc(fp)) != EOF)
{
printf("%2x", c);
++charArray[b][c];
++array[c];
b=c;
}
int k;
printf("\nSymbols frequency counter: \n");
for(k=0;k<256;k++) {
if(array[k] > 0 ) {
printf("char %2x: %d times \n", k, array[k]);
}
}
int y,z;
printf("Symbols after symbols frequency counter: \n");
for(y=0;y<256;y++){
for(z=0;z<256;z++){
if(charArray[y][z] > 0) {
printf("char %2x after char %2x: %.0f times\n", z, y, charArray[y][z]);
}
}
}
fclose(fp);
return 0;
EDIT: It's now good?