.exe 파일의 엔트로피를 입력으로 계산하려고합니다. 그러나, 나는 대답 대신에 0 값을 얻는다..exe 파일의 엔트로피를 계산할 수 없습니다.
파일의 엔트로피는 파일의 모든 문자 (pi * log (pi))의 합계로 이해할 수 있습니다. .exe 파일의 엔트로피를 계산하려고합니다. 그러나, 나는 '0'을 얻는 것을 끝내고있다. '.exe'파일에는 출력이 있습니다.
아래 코드는 제 코드입니다.
#include <stdio.h>
#include <stdlib.h>
#include "stdbool.h"
#include <string.h>
#include <conio.h>
#include <math.h>
#define MAXLEN 100
int makehist(char *S, int *hist, int len) {
int wherechar[256];
int i,histlen;
histlen=0;
for (i=0;i<256;i++)
wherechar[i]=-1;
for (i=0;i<len;i++) {
if (wherechar[(int)S[i]]==-1) {
wherechar[(int)S[i]]=histlen;
histlen++;
}
hist[wherechar[(int)S[i]]]++;
}
return histlen;
}
double entropy(int *hist, int histlen, int len) {
int i;
double H;
H=0;
for (i=0;i<histlen;i++) {
H-=(double)hist[i]/len*log((double)hist[i]/len);
}
return H;
}
void main() {
char S[100];
int len,*hist,histlen;
int num;
double H;
int i=0;
int count =0;
FILE*file = fopen("freq.exe","r");
while (fscanf(file,"%d",&num)>0)
{
S[i]=num;
printf("%d",S[i]);
i++;
}
hist=(int*)calloc(i,sizeof(int));
histlen=makehist(S,hist,i);
H=entropy(hist,histlen,i);
printf("%lf\n",H);
getch();
}
오 이런. 당신의 들여 쓰기가 어떻게 되었습니까? 읽을 수 없습니다. –
사람들에게 코드를 읽도록 요청할 때 더 잘 포맷하십시오. 들여 쓰기, 연산자 주위의 공백 (예 :'for (i = 0; i <256, i ++)') 등 – Almo
@MattiVirkkunen, @ Almo는 제안을 주셔서 감사합니다 – sam