You should give us an example maze to work with (why should I have to make one myself?).
size should be in UPPERCASE (as is the norm for macro names).
Is the maze SIZE columns and only SIZE - 1 rows? That's what your input/output code seems to say.
It looks like you could ditch the "flag" variable and simply use the break statement to exit the loop.
It doesn't look like you're using erow or ecol. They don't seem to be needed.
You should divide your program into functions.
Code:
int main(void) {
char maze[SIZE][SIZE];
int srow, scol;
read_maze(maze);
find_start(maze, &srow, &scol);
solve_maze(maze, srow, scol);
return 0;
}
Your switch cases are missing breaks! And it's very messy and hard to understand. Clearning it up a little still leaves rather incomprehensible code. Do you think a && b == '#' compares both a and b to '#'? It doesn't. If that's what you want, then you need to write a == '#' && b == '#'. Even fixing that, I still can't comprehend what you're trying to do here:
Code:
enum { EAST, SOUTH, WEST, NORTH };
switch (dir)
{
case EAST:
if ((m[x] [y+1] == '#' && m[x] [y-1]) == '#' && m[x+1][y] == ' ') x++;
else if ((m[x] [y+1] == '#' && m[x+1][y]) == '#' && m[x] [y-1] == ' ') { y--; dir = NORTH; }
else if ((m[x] [y-1] == '#' && m[x+1][y]) == '#' && m[x] [y+1] == ' ') { y++; dir = SOUTH; }
else if ((m[x] [y+1] == '#' && m[x] [y-1]) == ' ' && m[x+1][y] == '#') { y++; dir = SOUTH; }
else if ((m[x+1][y] == '#' && m[x] [y+1]) == ' ' && m[x] [y-1] == '#') { y++; dir = SOUTH; }
else if ((m[x] [y-1] == '#' && m[x+1][y]) == ' ' && m[x] [y+1] == '#') x++;
else if ((m[x] [y+1] == '#' && m[x] [y-1] && m[x+1][y]) == '#') dir = WEST;
break;
You also have to make sure you're not accessing outside the bounds of the array.