What's wrong with my code. It is giving segmentation fault as output

#include

using namespace std;

bool ratInMaze(char a[100][100], int sol[100][100], int i, int j, int m, int n){

if(i==m&&j==n){
sol[i][j]=1;

for(int i=0;i<=m;i++){
  for(int j=0;j<=n;j++){
    cout<<sol[i][j];
  }
  cout<<endl;
}
cout<<endl;
return true;

}

if(i>m||j>n||i<0||j<0){
return false;
}

if(a[i][j]==‘X’){
return false;
}

sol[i][j]=1;

bool rightSuccess = ratInMaze(a,sol,i,j+1,m,n);
bool downSuccess = ratInMaze(a,sol,i+1,j,m,n);
bool leftSuccess = ratInMaze(a,sol,i,j-1,m,n);
bool upSuccess = ratInMaze(a,sol,i-1,j,m,n);

if(rightSuccess||downSuccess||leftSuccess||upSuccess){
return true;
}

sol[i][j]=0;

return false;

}

int main()
{
int n,m;

cin>>m>>n;

char a[100][100];
int sol[100][100]={0};

for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>a[i][j];
}
}

bool k = ratInMaze(a,sol,0,0,m-1,n-1);
if(k==false)
{
cout<<"-1";
}
return 0;
}

add this condition also
otherwise stuck in a loop

if(sol[i][j]==1) 
  return false;

yeah no segmentation fault now but the code is not returning correct answer

after that it should give correct output

Modified Code

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.