Array walker C language.
Всем привет. Имеется такое задание:
Array Walker Write a program that computes a ”walk” (of a cute robot) across a 10x10 array. The array contains characters (all initially ’.’). The user can enter four different directions north, east, south, west, by entering the characters n,e,s,w to control the walk. If the user enters x the program exits. After each direction-command the array is printed with the walk being display by capital letter starting with A to Z. We use A for the starting point, with 25 remaining letters to denote the steps. After having used letter Z to denote a step, we wrap around and start again with A. To make the walk more interesting, the user is not allowed to revisit a location. In this case the program does not print the array, but prints ”You cannot go there!” - Yes, you can trap yourself. Starting in the upper left corner (position 0,0):
Вот что я уже сделал.
#include
#define M 26
#define N 10
#define K 10
int main()
{
char A[N][K],direction;
char let[M] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char start='A';
int x=0,y=0;
int i=0,j=0,m,k;
for(i=0; i
for(i=0; i
for(j=0; j
printf("\n");
}
k=0;
A[x][y]=let[k];
printf("enter direction:\n");
scanf("%c",&direction);
do{
if (direction == 's' && x==10 || direction=='e' && y==10 || direction=='w' && y==0 || direction=='n' && x==0){
printf("u cant go there\n");
for(i=0; i
printf("\n");}
}else if(direction=='s') {
x++;
k++;
A[x][y]=let[k];
for(i=0; i
printf("\n");}
}else if (direction=='e'){
y++;
k++;
A[x][y]=let[k];
for(i=0; i
printf("\n");}
}else if (direction=='w'){
y--;
k++;
A[x][y]=let[k];
for(i=0; i
printf("\n");}
}else if (direction=='n'){
x--;
k++;
A[x][y]=let[k];
for(i=0; i
printf("\n");}
}
printf("enter direction:\n");
scanf("%c",&direction);
} while (k!=26);
}
проблема такая. Почему-то после запроса одной команды, в следующий раз текс 'enter direction' отображается 2 раза.
проблема вторая. я так понимаю что условие для того, чтобы не возвращаться на уже посещенную позицию должно выглядеть как A[x++][y]!='.'(например для юга) . если я понял правильно, как мне это реализовать, куда мне впихнуть это условие? Прошу прощения, может звучит глупо, но я правда не понимаю этот момент.