배열 좌표 탐색
너만을
질문 제목 : 배열 좌표 탐색배열 좌표애서 탐색하는 법좀 알려주세요...질문 내용 :
배열에서 ↓찾아서 자동으로 오른쪽으로 이동 하려고 합니다..
그런데 찾기는 찾는데 이동이 안되네요...
소스에서 어떤게 문제가 인는거죠??
#include stdio.h
#include conio.h
#include windows.h
#include stdlib.h
#include time.h
#include dos.h
void gotoxy(int x, int y)
{
coord pos={x,y};
setconsolecursorposition(getstdhandle(std_output_handle), pos);
}
void back();
int arr[10][20]={
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,4,3,0,0,4,3,0,0,4,3,0,0,4,3,0,9,4,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,4,3,0,0,4,3,0,0,4,3,0,0,4,3,0,0,4,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,4,3,0,0,4,3,0,0,4,3,0,0,4,3,0,0,4,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
};
int main()
{
int c=0;
int x=0, y=0,i,j;
int ch;
for(i=0; i10; i++){
for(j=0; j20; j++){
if ( arr[i][j]==9) {
y=i;
x=j;
}
}
}
while(1){
back();
if(arr[y][x+1]==0)
{
arr[y][++x]=9;
arr[y][x-1]=0;
}
}
}
void back()
{
int a, b;
gotoxy(0, 0);
for(a=0; a10; a++)
{
for(b=0; b20; b++)
{
if(arr[a][b]==0)
printf(□);
else if(arr[a][b]==1)
printf( );
else if(arr[a][b]==3)
printf(☆);
else if(arr[a][b]==4)
printf(★);
else if(arr[a][b]==5)
printf(○);
else if(arr[a][b]==6)
printf(●);
else if(arr[a][b]==7)
printf(◇);
else if(arr[a][b]==9)
printf(↓);
}
printf(\n);
}
}