title: How can I sub-divide or split my 2D Array into smaller quadrants repeatedly?
body: <p>I'm trying to split a 2^n by 2^n 2D array into 4 quadrants. I then want to search these quadrants for pieces of information. If all the quadrant array elements = 1 or 0, then that quadrant can be left alone. If the quadrant has a mix of 1's and 0's, then I want to carry on splitting the array until I am left with a quadrant of only 1's or 0's (Even if that's a single array element). I understand that I must implement a recursive function, but I can't seem to figure out how... Here's what I have so far. Any help is greatly appreciated!</p>
  
  <pre><code>node* split(int **image_array, int width){
   node* root = NULL;
   int i, j;
   int black_pixel_NW = 0, black_pixel_NE = 0, black_pixel_SE = 0, black_pixel_SW = 0;
  
  
   if (width &gt;= 2){
  
  
       for (i = 0; i &lt; width/2; i++)   {
           for (j = 0; j &lt; width/2; j++){
               printf("(%d,%d) = %d\n", i, j, image_array[i][j]);
               if (image_array[i][j] == 0){
                   black_pixel_NW = ++black_pixel_NW;
               }
           }
       }
       printf("\nBlack pixels NW = %d\n", black_pixel_NW);
  
  
       for (i = width/2; i &lt; width; i++)   {
           for (j = 0; j &lt; width/2; j++){
               printf("(%d,%d) = %d\n", i, j, image_array[i][j]);
               if (image_array[i][j] == 0){
                   black_pixel_NE = ++black_pixel_NE;
               }
           }
       }
       printf("\nBlack pixels NE = %d\n", black_pixel_NE);
  
  
               for (i = width/2; i &lt; width; i++)   {
           for (j = width/2; j &lt; width; j++){
               printf("(%d,%d) = %d\n", i, j, image_array[i][j]);
               if (image_array[i][j] == 0){
                   black_pixel_SE = ++black_pixel_SE;
               }
           }
       }
      printf("\nBlack pixels SE = %d\n", black_pixel_SE);
  
  
       for (i = 0; i &lt; width/2; i++)   {
           for (j = width/2; j &lt; width; j++){
               printf("(%d,%d) = %d\n", i, j, image_array[i][j]);
               if (image_array[i][j] == 0){
                   black_pixel_SW = ++black_pixel_SW;
               }
           }
       }
       printf("\nBlack pixels SW = %d\n", black_pixel_SW);
  
       width = width / 2;
  
   }
  
   return root;}
  </code></pre>
  
  <p>The code will be for reading a binary image file, hence the black_pixel variables. black_pixel_NW means number of black pixels in the upper left quadrant. I have pointer stuff in the function as this information will eventually be stored in a quad tree.</p>