Hi this is my first post here and i'm fairly new to C programming.


So i'm trying to make a quadtree, and included in a header file is the node structure as follows:

Code:
 typedef struct tnode *tree; 
  
 struct tnode 
 { 
     tree *P; 
         tree *NW; 
     tree *NE; 
     tree *SE; 
     tree *SW; 
     char colour; 
     int size; 
     int x; 
     int y; 
 };
Also in the header file is my function declaration for making the quadtree:


Code:
tree makequadtree(tree node, int array[MAXSIZE][MAXSIZE], int size);
In my C file, I have called the function as follows:


Code:
makequadtree(node, my_2D_array, size);
However my quadtree function gives me a segmentation fault. I have pasted the relevant part of this function:


Code:
tree makequadtree(tree node, int array[MAXSIZE][MAXSIZE], int s) 

 { 
   int q,w,a,b;  
   int NW_array[MAXSIZE][MAXSIZE]={0}, NE_array[MAXSIZE][MAXSIZE]={0}; 
   int SE_array[MAXSIZE][MAXSIZE]={0}, SW_array[MAXSIZE][MAXSIZE]={0}; 
  
   node->size = s; 
   node->NW = NULL; 
   node->NE = NULL; 
   node->SE = NULL; 
   node->SW = NULL; 
  
   if(get_colour(array, s) == 'G') 
   { 
  
   node->colour = 'G'; 
  
    //NW BLOCK: 
   for(q=0,w=0, a=0,b=0; w<s/2, b<s/2; q++, a++) 
     { 
       NW_array[q][w] = array[a][b]; 
       if(q==(s/2)-1) 
        { 
          q=-1; 
          a=-1; 
          w++; 
          b++; 
        } 
     } 
   
   makequadtree(node->NW, NW_array, s/2); 
  
    //NE BLOCK: 
   for(q=0,w=0, a=2,b=0; w<s/2, b<s/2; q++, a++) 
     { 
       NE_array[q][w] = array[a][b]; 
       if(q==(s/2)-1) 
       {  
         q=-1; 
         a=1; 
         w++; 
         b++; 
       } 
     } 
  
  
   makequadtree(node->NE, NE_array, s/2); 
  
     //SE BLOCK: 
   for(q=0,w=0, a=2,b=2; w<s, b<s; q++, a++) 
     { 
       SE_array[q][w] = array[a][b]; 
       if(q==(s/2)-1) 
       { 
         q=-1; 
         a=1; 
         w++; 
         b++; 
       } 
     }   
  
    makequadtree(node->SE, SE_array, s/2); 
  
      //SW BLOCK: 
    for(q=0,w=0, a=0,b=2; w<s, b<s; q++, a++) 
      { 
        SW_array[q][w] = array[a][b]; 
        if(q==(s/2)-1) 
        { 
          q=-1; 
          a=1; 
          w++; 
          b++; 
        } 
      } 
  
    makequadtree(node->SW, SW_array, s/2); 
  
   } 
   else if(get_colour(array, s) == 'B') 
     { 
       node->colour = 'B'; 
     } 
  
   else node->colour = 'W'; 
     
 }
The problem seems to lie in 'node->size = s;' and any other time I try to pass a value to a node. Perhaps I have defined my structure incorrectly?


Any help would be much appreciated!
Pedro.