Rat chases its cheese(Please find what's wrong)

My solution: My code

Question link: Question

Problem with my code: My solution is working when only right and down move are allowed but when rat can move in all direction it’s giving segmentation fault.

Please help!!! :thinking: