gpt4 book ai didi

计算文件中 8 位符号的频率

转载 作者:行者123 更新时间:2023-11-30 15:22:14 25 4
gpt4 key购买 nike

我有下一个挑战,需要一点帮助;)

Program to write: The file is treated as a row of 8-bit symbols.

  1. Count the frequency (incidence) of these symbols
  2. 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).

所以我写了一点代码;这是:

主要:

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;

编辑:现在好吗?

最佳答案

Now i need a help, what will be the best way to write a 2* point?

与您当前正在做的几乎相同,除了您需要使用二维数组并跟踪您看到的前一个字符,例如

++charArray[b][c];
b = c;

当然,在打印数组时您需要处理两个维度。

关于计算文件中 8 位符号的频率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29266693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com