So I need to make a code that finds the length of the minimal path in a maze.
The maze is an NxN matrix, starting point is (0,0) and ending point is (N,N), if the cell contains 1 I can go through it, if it's 0 I cannot. The maze may or may not have a solution.
This is my code so far, assuming it has a solution:
int path_finder(int maze[][N], int n, int row, int col)    // n equal N
{
int i, j, pth;
if (row == n-1 && col == n-1)    // Return 0 if I get to goal
  return 0;
if (col < 0 || row < 0 || row > n-1 || col > n-1)    // Same
  return n*n;
if (maze[row][col] == 0)    // Return big number to make sure it doesn't count
  return n*n;
maze[row][col] = 0;
pth = min( 1+path_finder(maze,n, row+1, col),    // Assume I already know the path
            1+path_finder(maze,n, row-1, col),    // from the next starting point
            1+path_finder(maze,n, row, col+1),    // just add 1 to it
            1+path_finder(maze,n, row, col-1)  );
maze[row][col] = 1;
return pth;
}
I always get N^2+1, I assume it only counts the last argument I send to the min function, but I don't know how to fix it?
 
    