And after editing the code as following to what you told me, I got a holly error which is:
error C2082: redefinition of formal parameter 'count'
error C2198: 'find_path' : too few arguments for call
Code:
#include <stdio.h>
#define FALSE 0
#define TRUE 1
#define NROWS 7
#define MCOLS 7
// Symbols:
// '1' = open
// '0' = blocked
// 'S' = start
// 'G' = goal
// '+' = path
// 'x' = bad path
char maze[NROWS][MCOLS] = {
"1111000",
"0111110",
"0101100",
"1101100",
"0111010",
"010101G"
};
void display_maze(void);
int find_path(int x, int y,int *count);
int main(void)
{
int count=0;
display_maze();
if ( find_path(0, 0,&count) == TRUE )
printf("Success!\n");
else
printf("Failed\n");
display_maze();
printf("You path lenght is: %d\n", count);// used the "count" to sum all the "1" in the path and print the result(path's length)at the end//
return 0;
}
// main()
void
display_maze(void)
{
int i;
printf("MAZE:\n");
for ( i = 0; i < NROWS; i++ )
printf("%.*s\n", MCOLS, maze[i]);
printf("\n");
return;
}
int
find_path(int x, int y,int *count)
{
int count=0;
// If x,y is outside maze, return false.
if ( x < 0 || x > MCOLS - 1 || y < 0 || y > NROWS - 1 ) return FALSE;
// If x,y is the goal, return true.
if ( maze[y][x] == 'G' ) return TRUE;
// If x,y is not open, return false.
if ( maze[y][x] != '1') return FALSE;
// Mark x,y part of solution path.
maze[y][x] = '+';
++*count;
// If find_path North of x,y is true, return true.
if ( find_path(x, y - 1) == TRUE ) return TRUE;
// If find_path East of x,y is true, return true.
if ( find_path(x + 1, y) == TRUE )return TRUE;
// If find_path South of x,y is true, return true.
if ( find_path(x, y + 1) == TRUE ) return TRUE;
// If find_path West of x,y is true, return true.
if ( find_path(x - 1, y) == TRUE ) return TRUE;
// Unmark x,y as part of solution path.
maze[y][x] = 'x';
return FALSE;
}
// find_path()
Any help for please??
And for another specific required- as I already have made a code for finding a path, how could I develop to show me all the leading path to the exit if possible? (Supposing the input matrix-maze has three paths way leading to its exit, not only one), I'm not making the things go hardly, just trying to get the code more efficient and in the same time as a new programmer to be known of what development steps should be taken to develop your prime code properly.
thanks