This code of ratmaze shows runtime error

#include
using namespace std;
void printInaMaze(char maze[4][4], int sol[4][4],int sr, int sc,int er,int ec){
if(sr==er and sc==ec){
sol[sr][sc]=1;
for(int i=0;i<=er;i++){
for(int j=0;j<=ec;j++){
cout<<sol[i][j]<<" “;
}
cout<<endl;
}
cout<<”######################################"<<endl;
return ;
}
if(sr>er and sc>ec){
return ;
}
if (maze[sr][sc]==‘X’){
return ;
}
sol[sr][sc]=1;
printInaMaze(maze,sol,sr+1, sc, er,ec);
printInaMaze(maze,sol,sr, sc+1, er,ec);
sol[sr][sc]=0;

}

int main(){
char maze[][4] = {
{‘0’,‘0’,‘0’,‘0’},
{‘0’,‘0’,‘0’,‘X’},
{‘0’,‘0’,‘0’,‘0’},
{‘0’,‘X’,‘0’,‘0’},
};
int sol[4][4] = {0};
printInaMaze( maze,sol,0,0,3,3);
return 0;

}

u need to check out of bound condition before trying to print

if(maze[sr][sc] == '0'){
    sol[sr][sc] = 1;
    printInaMaze(maze, sol, sr + 1, sc, er, ec);
    printInaMaze(maze, sol, sr, sc + 1, er, ec);
    sol[sr][sc] = 0;
}

add the is condition and add a return statement at the end of the function

updated 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.