我刚刚写了一些C代码来检查一个将死(在国际象棋中),但我真的无法理解我的语法有什么问题,这是编译错误:
main.c:2:30: error: expected ';', ',' or ')' before 'board'
int is_check(const char[][8] board,int i,int j){
^ main.c:117:27: error: expected ';', ',' or ')' before 'board'
int check(const char[][8] board)
这是我的代码:
#include <stdio.h>
int is_check(const char[][8] board,int i,int j){
int row = i;
int clmn = j;
//check clmn , up
do{
i--;
}
while(board[i][j] == 'z');
if(i>=0){
if(board[i][j] == 'H'){
return 1;
}
}
i = row;//init
//check clmn , down
do{
i++;
}
while(board[i][j] == 'z');
if(i<8){
if(board[i][j] == 'H'){
return 1;
}
}
i = row;//init
//check row , up
do{
j--;
}
while(board[i][j] == 'z');
if(j>=0){
if(board[i][j] == 'H'){
return 1;
}
}
j = clmn;//init
//check row , down
do{
j++;
}
while(board[i][j] == 'z');
if(j<8){
if(board[i][j] == 'H'){
return 1;
}
}
j = clmn;//init
//check orib!4
do{
j++;
i++;
}
while(board[i][j] == 'z');
if(j<8 && i<8){
if(board[i][j] == 'H'){
return 1;
}
}
j = clmn;
i = row;
//check orib!1
do{
j++;
i--;
}
while(board[i][j] == 'z');
if(j<8 && i>=0){
if(board[i][j] == 'H'){
return 1;
}
}
j = clmn;
i = row;
//check orib!3
do{
j--;
i++;
}
while(board[i][j] == 'z');
if(j>=0 && i<8){
if(board[i][j] == 'H'){
return 1;
}
}
j = clmn;
i = row;
//check orib!2
do{
j--;
i--;
}
while(board[i][j] == 'z');
if(j>=0 && i>=0){
if(board[i][j] == 'H'){
return 1;
}
}
return 0;
}//end func
int check(const char[][8] board)
{
int i = 0;
int j = 0;
for(;i<8;i++){
for(;j<8;j++){
if(board[i][j] == 'q')
return is_check(board,i,j);
}
}
return 0;
}
int main(){
char x[8][8] ={{'R','z','B','Q','H','z','q','R'},
{'A','A','A','A','z','z','A','A'},
{'z','z','z','d','z','z','D','z'},
{'z','z','z','z','z','z','z','b'},
{'z','z','z','z','a','z','z','z'},
{'a','z','z','a','z','z','z','z'},
{'z','a','a','z','z','a','a','a'},
{'r','d','b','z','h','z','z','r'}};
printf("%d",check(x));
return 0;
}
答案 0 :(得分:2)
因为它应该是
const char board[][8];