Counting frequency of strings in 2D array in C
I am somewhat stuck on a piece of code that I'm hoping I can get some insight on here. Essentially I am reading an input file, grabbing the bit values and storing them. in a 2d array.What I'm trying to accomplish is finding the number of occurrences of each string in the 2d array.For example, Here is what is being stored in the 1st couple of entries in the 2d array sortBuffer[][]
Code:
111000101
110000101
111110000
101011000
000000010
101001000
So what I need to accomplish, is creating a count array that will tell me the number of times, say 111000101, or 110000101 occurs within the sortBuffer. Since it's a 2D array I'm working with, I'm not really sure how to compare the entire string. Any help with this would be greatly appreciated. Thank you all in advance.As an additional step, I need to organize the array by bit values, starting with
000000001
000000010
000000011
000000100
and so on...
Code:
int getBitVal(unsignedchar*keyStrBin,int keyIndex){
int keyMod = keyIndex %8;
int keyIn = keyIndex /8;
return(((keyStrBin[keyIn])>>(7-(keyMod)))&1);
}
void test(FILE*inputFile){
int nRead;
size_t fSize = size(inputFile);
unsignedchar*inBuffer = malloc(fSize *sizeof(unsignedchar));
memset(inBuffer,0, fSize);
nRead = fread(inBuffer,1, fSize, inputFile);
int h =0;
int b =0;
int m =9
int n =24720
char sortBuffer[m][n / m];
for(i =0; i < fSize *8; i++){
sortBuffer[b][h]= getBitVal(inBuffer, i);
b++;
if(i % m ==0&& i !=0){
b =0;
h++;
}
}
//This is where I need to count the number of times any given string occurs within the sortBuffer char.