Hi!!! I'm trying to pass 2d array to function and i can't.
In general i'm trying to print chess board in action.
The board is an integer.I need a function that gets 2d array in specific place and returns correlatedm char.
const int pawn = 1;
const int rook = 2;
const int knight = 3;
const int bishop = 4;
const int queen = 5;
const int king = 6;
)
my attemps:
#include<stdio.h>
int board[8][8];
int x;
int y;
void setup_board()
{
// Normal board setup
board[0][0]=2;
board[0][1]=3;
board[0][2]=4;
board[0][3]=5;
board[0][4]=6;
board[0][5]=4;
board[0][6]=3;
board[0][7]=2;
board[1][0]=1;
board[1][1]=1;
board[1][2]=1;
board[1][3]=1;
board[1][4]=1;
board[1][5]=1;
board[1][6]=1;
board[1][7]=1;
board[2][0]=0;
board[2][1]=0;
board[2][2]=0;
board[2][3]=0;
board[2][4]=0;
board[2][5]=0;
board[2][6]=0;
board[2][7]=0;
board[3][0]=0;
board[3][1]=0;
board[3][2]=0;
board[3][3]=0;
board[3][4]=0;
board[3][5]=0;
board[3][6]=0;
board[3][7]=0;
board[4][0]=0;
board[4][1]=0;
board[4][2]=0;
board[4][3]=0;
board[4][4]=0;
board[4][5]=0;
board[4][6]=0;
board[4][7]=0;
board[5][0]=0;
board[5][1]=0;
board[5][2]=0;
board[5][3]=0;
board[5][4]=0;
board[5][5]=0;
board[5][6]=0;
board[5][7]=0;
board[6][0]=1;
board[6][1]=1;
board[6][2]=1;
board[6][3]=1;
board[6][4]=1;
board[6][5]=1;
board[6][6]=1;
board[6][7]=1;
board[7][0]=2;
board[7][1]=3;
board[7][2]=4;
board[7][3]=5;
board[7][4]=5;
board[7][5]=4;
board[7][6]=3;
board[7][7]=2;
}
char print_piece(board[x][y]);
int main()
{
setup_board() ;
char letter;
letter=print_piece(board[6][6]);
printf("%c\n");//to check an output
scanf("%d",&x);//to stop the compiler
return 0;
}
char print_piece(board[x][y])
{
int choice;
char piece;
board[x][y]=choice;
switch(choice)
{
case 1:
piece='P';
break;
case 2:
piece='R';
break;
case 3:
piece='N';
break;
case 4:
piece='B';
break;
case 5:
piece='Q';
break;
case 6:
piece='K';
break;
default:
piece=' ';
break;
}
return piece;
}
The compiler(DEV C++)" can't use print_piece as a function".Why??
How do I use it? thanx!!!