i have a function that adds escape codes to a string so it colours the piece selected red. if i try and move the piece to an invalid square or invalid move it then de-colours the piece
Code:
void colour_selected_piece(char board[][ROW_MAX + 1][MESSAGE], char code[], int current_player, int x, int y)
{
if (strlen(code) >= strlen(CLEAR_COLOUR))
{
//strcat(code, COLOUR_WHITE_PIECE);
//printf(" %s", code);
current_player ? update_board_array(board, strcat(code, COLOUR_BLACK_PIECE), x ,y) :
update_board_array(board, strcat(code, COLOUR_WHITE_PIECE), x, y);
}
else
{
strcpy(board[x][y], "test");
current_player ? update_board_array(board, "b", x, y) : update_board_array(board, "w", x, y);
}
clear_screen();
draw_board(board, current_player);
}
it all works as far as the screen says however if i try and select the piece again it says it isnt there. upon doing some strategic for loops and printf's i have discovered that the length of the string (should just be a single letter) at the given board location is 9. Obviously there is some escape code left over.
how can i reset the length of the array for the string at that position to zero copying a string of "" didn't work
many thanks
coop