new programmer needs advice. I've created a 5 by 5 board using 2d arrays. However I want to fill the array table with 4 possible letters x, y, z.
createBoard()
{
char myArray[5][5];
int i,j;
for(i=0; i < ROW; i++){
for(j=0; j < COL; j++){
if(myArray[0][1]){
myArray[i][j] = '0';
printf("%c ", myArray[i][j]);
}
}
printf("\n");
}
printf("%d\n", myArray[i][i]);
getchar;
return 0;
}
int main(int argc, char *argv[]){
createBoard();
}
As of right now, all this does is fill the 5 by 5 with 0's. I want it to have a mix of x,y and z's. Would I be better of just filling each array myself like
char myArray[5][5] =
{
{z,y,z,x,y},
{y,y,x,x,z},
}
and so on? or is there a better way considering later on I need to create functions to take in user input and manipulate the positions of the x, y, and z characters.
Cheers for any guidance
In function ‘createBoard’: warning: statement with no effect [-Wunused-value],In function ‘createBoard’: warning: array subscript is above array bounds [-Warray-bounds],warning: ‘myArray’ is used uninitialized in this function [-Wuninitialized], …getchar;should have no effect, you wantgetchar();. In any case, I'd suggest you separate the filling of teh array from the output.