I am currently trying to read a file and calculate the frequencies of 1 byte equivalent numbers (0 to 255). I want to do the same for 2 byte equivalent numbers (0 to 65535)
Simplified version of what I have:
int length = 256; //any value 256>
long long values[length]
char buffer[length]
int i,nread;
fileptr = fopen("text.txt", "rb");
for (i=0; i<length; i++){ values[i]=0 }
while((nread = fread(buffer, 1, length, fileptr)) > 0){
for(i=0;i<nread;i++){
values[(unsigned char)buffer[i]]++;
}
}
fclose(fileptr);
for(i=0;i<length;i++{
printf("%d: %lld",i, values[i]);
}
What I am getting now:
0: 21
1: 27
...
255: 19
What I want:
0: 4
1: 2
...
65535: 3