Segmentation Fault

my code is running into infinite recursion, please correct it:- https://ide.codingblocks.com/s/278947

Refer this code to check how loop is avoided.
Rat can move in all4 directions
Consider this
from (i,j),
move down by 1
then move right by 1
then move up by 1
and then move left by 1.
after these moves u will again reach to same state.
now if u again proceed from that state then u will again take these same steps and this will keep happening again n again . and u will stuck in an infinite loop.