[問題] Problem about find path for maze
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Embercardero.
Codeblock.
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
none
問題(Question):
Segementation error(I'm a novice of C, I don't understand what the
information really means.)
餵入的資料(Input):
A 7-by-10 matrix with 1 as wall, 0 as path
預期的正確結果(Expected Output):
The route to the exit of the mazz in the upper-left of the matrix ,
maze[1][1].The path crossed should have been labled by 2.
錯誤結果(Wrong Output):
In embarcadero:
"problem raised exception class$c00000FD with message-
stack overflow at 0x0040141d.
In Codeblock:
it simply addressed "segementation error"
程式碼(Code):(請善用置底文網頁, 記得排版)
int findpath(int x,int y);
int maze[7][10]=
{
1,1,1,1,1,1,1,1,1,1,
1,0,1,0,1,0,0,0,0,0,
1,0,1,0,1,0,1,1,0,1,
1,0,1,0,1,1,1,0,0,1,
1,0,1,0,0,0,0,0,1,1,
1,0,0,0,1,1,1,0,0,1,
1,1,1,1,1,1,1,1,1,1,
};
int main()
{
int i,j;
findpath(5,8);
for(i=0;i<7;i++)
{
for(j=0;j<10;j++)
{
printf("%d ",maze[i][j]);
printf("\n");
}
}
system("pause");
return 0;
}
int findpath(int x,int y)
{
if(x==1&&y==1)
{
maze[x][y]=2;
return 1;
}
else if(maze[x][y]==0)
{
maze[x][y]==2;
if( (findpath(x-1,y)+findpath(x+1,y)+findpath(x,y-1)+findpath(x,y+1))>0)
{
return 1;
}
else
{
maze[x][y]=0;
return 0;
}
}
else
return 0;
}
補充說明(Supplement):
In codepad, the output indicates "time out".
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.168.250.150
※ 編輯: bethlehem 來自: 118.168.250.150 (02/19 19:27)
※ 編輯: bethlehem 來自: 118.168.250.150 (02/19 19:27)
→
02/19 20:28, , 1F
02/19 20:28, 1F
→
02/19 20:30, , 2F
02/19 20:30, 2F
→
02/19 20:31, , 3F
02/19 20:31, 3F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章