为什么if语句里明明arr[i]和j数值相等,却不执行。
int is_full(char arr[N])
{
int b;
int i;
int j=1;
int k=1;
for(i=0;i<9;i++)
{
printf("。%d。",j);
if(arr[i]==j)//Judge if there is a number.
k++;
else
k=k;
printf("。%c。",arr[i]);
printf("。%d。\n",k);
j=j+1;
}
//printf("%d",k);
if(k!=1)//The chessboard is not full.
b=1;
else
b=2;//It is a draw, b=2.
return b;
}
arr[i]的内容类型是char,而j的类型是int
例如数字1,char a = ‘1’,a的值实际上是0x31(参照ascii码表)。而int a = 1,a的值就是0x01
int is_full(char arr[N])
{
int b;
int i;
char j='1';
int k=1;
for(i=0;i<9;i++)
{
if(arr[i]==j)//Judge if there is a number.
k++;
else
k=k;
j= (char) ( '2' + i );
}
if(k!=1)//The chessboard is not full.
b=1;
else
b=2;//It is a draw, b=2.
return b;
}
我把j变成了这种形式就可以运行判断了
j= (char) ( '2' + i );