hey dudes pls help me on this. My program is crashing on the following piece of code

When i make 1 recurssive function to work, the program works without crashing. So I would really need help in spotting the mistake I have done.

Incase if you want to know what im trying to do-
I have wrote a function to spot all pixels of an image and it is used to find the centre of the image. Some variables like pixtot and xt are declared as global variables.

void neighbour(int x, int y){
if(s[y][x+1]<192){ 
        xt=xt+(x+1);
        neighbour((x+1),y); 
        pixtot++; 
    }
    if(s[y][x-1]<192){ 
        xt=xt+(x-1); 
        //neighbour((x-1),y);  //<- crashes when comment slashes are taken out
        pixtot++;
    }
    if(s[y+1][x]<192){ 
        yt=yt+(y+1);
        //neighbour(x,(y+1)); //<- crashes when comment slashes are taken out
        pixtot++; 
    }
    if(s[y-1][x]<192){ 
        yt=yt+(y-1); 
        //neighbour(x,(y-1)); //<- crashes when comment slashes are taken out
        pixtot++; 
}
}
    }

Thanks

Are you sure each time during recursion the value for x and y are what you expect to pass to the neighbour() function, i was wondering negative values for x and y or the values greater than the index of S[y][x] . Like y being 1000 and x being 5000, if we suppose the array being declared as int S[200][500] .

Thanks supersonic for the post.
yes it was a global variable that was declared as zero caused the problem. After making it as 1 fixed the crash :)

Thanks again. ;)

This question has already been answered. Start a new discussion instead.