I'm running into an error and I do not know how to fix it.
The essence of this function is to take a user's coordinate and input the player's symbol into the chosen coordinate. I did this by taking the input as a char, using strcmp to compare it to one of the 9 coordinate spaces, and then converting it into an integer using if statements. It would then input the player's symbol into this space. However, I wanted to make sure that the user is not inputting invalid coordinates. The problem is it keeps saying the input is invalid. I tried debugging using "A1". I checked strcmp and it resulted in 0. I checked invalid and it resulted in 0. I then checked row_move and column_move and they're getting assigned to the correct value of [0][2]. However, I did notice initially when I input A1, the column_move value is extremely high arbitrary number. Can someone help me figure this out?
void Player1Move()
{
char p1move[2];
int row_move, column_move, invalid;
row_move = 0;
column_move = 0;
invalid = 0;
printf("It's Player 1's turn!\n");
printf("What's your move?\n");
int rescheck;
do
{
printf("Enter your move ");
scanf("%s", p1move);
printf("YOUR MOVE IS %s\n", p1move);
printf("Check Invalid: %d\n", invalid);
rescheck = strcmp(p1move,"A1");
printf("Check String A1: %d\n", rescheck);
printf("Row: %d\n", row_move);
printf("Column: %d\n", column_move);
if(strcmp(p1move,"A1") == 0)
{
row_move = 2;
column_move = 0;
} else if(strcmp(p1move, "A2") == 0)
{
row_move = 1;
column_move = 0;
} else if(strcmp(p1move, "A3") == 0)
{
row_move = 0;
column_move = 0;
} else if(strcmp(p1move, "B1") == 0)
{
row_move = 2;
column_move = 1;
} else if(strcmp(p1move, "B2") == 0)
{
row_move = 1;
column_move = 1;
} else if(strcmp(p1move, "B3") == 0)
{
row_move = 0;
column_move = 1;
} else if(strcmp(p1move, "C1") == 0)
{
row_move = 2;
column_move = 2;
} else if(strcmp(p1move, "C2") == 0)
{
row_move = 1;
column_move = 2;
} else if(strcmp(p1move, "C3") == 0)
{
row_move = 1;
column_move = 2;
} else
{
invalid = 1;
}
/* check if board space is available */
if(invalid == 1 || board[row_move][column_move] != ' ')
{
printf("That is not a valid space, please pick a new space\n");
} else
{
board[row_move][column_move] = PLAYER1;
break;
}
} while(board[row_move][column_move] != ' ');
}
Edit 2:
I edited the function and still producing the same error.
It's Player 1's turn!
What's your move?
Enter your move A1
Move is [0][4196901]
Check Invalid: 0
String: A1
That is not a valid space, please pick a new space
Enter your move
This is what happens when I initially put in A1, I'm still getting this error. I had changed the char size and updated the scanf. I had checked to see if anything is being affected such as the row and column choices along with the invalid check. As shown here, there seems to be an error with column_move and it's still an arbitrary number.