I get this warning when trying to compile a code snippet from the net with GCC GNU compiler.
Code:
: warning: array subscript has type char [-Wchar-subscripts]
arr[0] = (int)tolower(strMove[0]) - 'a';//letter here
^
: warning: array subscript has type char [-Wchar-subscripts]
arr[1] = (int)tolower(strMove[1]) - '0';
^
: warning: array subscript has type char [-Wchar-subscripts]
arr[2] = (int)tolower(strMove[2]) - 'a';//letter here
^
: warning: array subscript has type char [-Wchar-subscripts]
arr[3] = (int)tolower(strMove[3]) - '0';
^
Compilation finished successfully.
I roughly think it has something to do with signed and unsigned char conflict? I don't understand it though and have tried to fix it but without success.
Code:
int GetMove(int arr[]) {
int count = 0;
int i,j;
int validInputArr[ROW_SIZE] = {0,1,2,3,4,5,6,7};
String strMove;
String strResign = "resign";
printf("Enter coordinates in the form g4e4\n");
printf("Enter resign to resign.\n");
gets(strMove);
if(StringCompare(strMove, strResign) == 1) {
return RESIGN;
} else if (strlen(strMove) != 4 ) {
return INVALID;
}
//Convert the chars to ints, which gives ascii numbers. So then convert to
//the decimal value by subtracting the base.
arr[0] = (int)tolower(strMove[0]) - 'a';//letter here
arr[1] = (int)tolower(strMove[1]) - '0';
arr[2] = (int)tolower(strMove[2]) - 'a';//letter here
arr[3] = (int)tolower(strMove[3]) - '0';
for(i=0;i<4;i++) {
for(j=0;j<ROW_SIZE;j++) {
if(arr[i] == validInputArr[j]) {
count++;
}
}
}
if(count != 4) {
return INVALID;
}else {
printf("Move piece from %i:%i to %i:%i\n", arr[0], arr[1], arr[2], arr[3]);
return VALID;
}
return 1;
}//End GetMove
I am grateful for help to fix it,many thanks.