title: Counting Frequency of Strings in 2D Array in C
body: <p>I am somewhat stuck on a piece of code that I'm hoping I can get some insight on here.</p>
  
  <p>Essentially I am reading an input file, grabbing the bit values and storing them. in a 2D array.</p>
  
  <p>What I'm trying to accomplish is finding the number of occurrences of each string in the 2D array.</p>
  
  <p>For example, Here is what is being stored in the 1st couple of entries in the 2d array <code>sortBuffer[][]</code></p>
  
  <pre><code>111000101
  110000101
  111110000
  101011000
  000000010
  101001000
  </code></pre>
  
  <p>So what I need to accomplish, is creating a count array that will tell me the number of times, say <code>111000101</code>, or <code>110000101</code> occurs within the <code>sortBuffer</code>.</p>
  
  <p>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.</p>
  
  <p>As an additional step, I need to organize the array by bit values, starting with </p>
  
  <pre><code>000000001
  000000010
  000000011
  000000100  and so on...
  </code></pre>
  
  <hr>
  
  <pre><code>int getBitVal(unsigned char *keyStrBin, int keyIndex) {
  
      int keyMod = keyIndex % 8;  
      int keyIn = keyIndex / 8;
  
      return (((keyStrBin[keyIn]) &gt;&gt; (7 - (keyMod))) &amp; 1);
  }
  
  void test(FILE *inputFile) {
      int nRead;
      size_t fSize = size(inputFile);
      unsigned char *inBuffer = malloc(fSize * sizeof (unsigned char));
      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 &lt; fSize * 8; i++) {
          sortBuffer[b][h] = getBitVal(inBuffer, i);
          b++;
          if (i % m == 0 &amp;&amp; i != 0) {
              b = 0;
              h++;
          }  
      }
  
  //This is where I need to count the number of times any given string occurs within the `sortBuffer` `char`.
  </code></pre>