title: Get the exit of maze using stack in C
body: <p>I have an algorithm that search for a exit of a maze using recursive function , how i pass this to a function without recursive but using stack?What this algorithm do is basically , try to found the exit of  a matriz , if the next step is 0 or if has already been covered comeback and try another path, but a i need to change the recursive function to a function using stack instead of recursion how i do that?</p>
  <pre><code>    void print_maze(char **maze, int width, int height) {
  
  for (int i=0; i&lt;13; i++ ){
    for (int j=0; j&lt;10; j++ )
    {
       printf (&quot;%d&quot;, maze[i][j]);
    }
  printf(&quot;\n&quot;);
  }
  }
  
  int maze(int x_current, int y_current,char **mazeHere, int height,int width)
  {
      if (x_current &lt; 0 || x_current &gt;= width || y_current &lt; 0 || y_current &gt;= height)
          return 0;
  
          char here = mazeHere[x_current][y_current];
          if (here == 3)
          return 1;
  
          if(here == 0 || here == 2)
              return 0;
  
  
          mazeHere[x_current][y_current] = 2;
           if(maze(x_current ,y_current-1,mazeHere,height,width))return 1;
          if(maze(x_current+1,y_current,mazeHere,height,width))return 1;
          if(maze(x_current,y_current+1,mazeHere,height,width))return 1;
  
            if(maze(x_current-1,y_current,mazeHere,height,width))return 1;
  
  
  
         else{ mazeHere[x_current][y_current] = 1;
              return 0;
         }
  
  }
  
  
  int main(void)
  {
  char matriz [13][10]={
  {0,0,0,0,0,0,0,0,0,0},
  {0,0,1,1,1,1,1,0,0,0},
  {0,0,1,0,0,0,1,0,0,0},
  {0,0,1,0,0,0,1,0,0,0},
  {1,1,1,0,1,1,1,1,1,0},
  {0,1,0,0,1,0,0,0,0,0},
  {0,1,1,0,1,1,1,0,0,0},
  {0,0,1,0,1,0,0,0,1,0},
  {0,0,1,0,0,0,1,1,1,0},
  {0,0,1,1,1,1,1,0,0,0},
  {0,0,0,0,0,0,1,0,0,0},
  {0,0,0,0,0,0,1,1,1,3},
  {0,0,0,0,0,0,0,0,0,0},};
  int b= 0;
  int height = 10;
  int width = 13;
  int p = 0;
  int o = 0;
  char **a = malloc(width * sizeof(char*));
  for(int x = 0; x&lt; width; x++){
      a[x] = malloc(height * sizeof(char));
  }
  
  
  for (int i=0; i&lt;13; i++ ){
    for (int j=0; j&lt;10; j++ )
    {
        a[i][j]= matriz[i][j];
    }
  
  }
  
  
  
  int res = maze(4,0,a,height,width);
      puts(res ? &quot;success!&quot; : &quot;no luck!&quot;);
  print_maze(a, width, height);
  return 0;
  }
  </code></pre>