I am building a c program to select and move a number in an array.My aim is to connect 2 pairs of same number in the array. But I am not sure why the selected number be can't moved. Need help, thanks in advance.
Code:
void playgame(char box[ROW][COL])
{
int x, y, choice2,num,direction=0;
char input;
do{
printf("Please select a number (1-7) : ");
scanf("%i",&num);
if(num==0||num >7)
{
printf("Invalid!\n");
}
else
{
printf("\nNumer %i is currently selected!\n", num);
}
}while(num==0||num >7);
printf("\n[1]Move\n[2]Sign out\n");
printf("\nEnter choice: \n");
scanf("%d",&choice2);
switch(choice2)
{
case1:
{
printf("Press 'e' to go up\n");
}
{
printf("Press 'd' to go right\n");
}
{
printf("Press 's' to go left\n");
}
{
printf("Press 'x' to go down\n");
}
fflush(stdin);
scanf("%c",&input);
break;
case2: printf("Bye!\n");
}
for(x=0; x<9; x++)
for(y=0; y<9; y++)
{
if(input =='e')
if(box[x][y]==num)
{
box[--x][y] =num;
}
if(input =='d')
if(box[x][y]==num)
{
box[x][++y] = num;
}
if(input =='s')
if(box[x][y] == num)
{
box[x][--y] = num;
}
if(input =='x')
if(box[x][y]==num)
{
box[++x][y] = num;
}
}
} |