typedef struct piece Piece;
struct piece{
char color;
char symbol;
};
int readPiece(Piece * p[]);
// Because my code is quite long . I didn't put all of them here.
int main(void){
int row = 0;
int col = 0;
Piece input[LEN][LEN];
readPiece(input);
return 0;
}
//read in 16*2 specific characters .
int readPiece(Piece * p[]){
int row = 0;
int col = 0;
while(row < LEN){
col = 0;
while(col < LEN){
scanf("%c%c",&(p[row][col] .color), &(p[row][col].symbol));
if((p[row][col].color == 'R' || p[row][col].color == 'G' || p[row][col].color == 'B' || p[row][col].color == 'Y') && (p[row][col] . symbol == '*' || p[row][col].symbol == '^' || p[row][col].symbol == '#' || p[row][col].symbol == '$')){
getchar();
}else{
return 0;
}
col ++;
}
row ++;
}
return 1;
}
// I just start learning C language. I try to pass a 2d struct by pointer into a function but when I compile it , it shows 'incompatible pointer types passing'. So I wanna ask what's the right way to pass a 2d struct into a function and why mine is not working. Thanks.
LENand include<stdio.h>, but that's about all. Providing more would not have been good. So well done on that. Why don't you useint readPiece(Piece p[LEN][LEN]);? It seems like a reasonable way to pass a 2D array of a structure type. (You don't useroworcolin your reducedmain().)int *p[]notation denotes an array of pointers toint. What you've got inmain()is not an array of pointers toint, but a 2D array ofint. These are not the same; they're not even all that similar — but, just to make sure you get the maximum confusion out of it all, you use the same notationarray[index1][index2]to access elements of both!