I need help trying to generate a 2D array (20×20 grid) with O’s and X’s. I’m later going to replace these with images to build somewhat of a map/grid. But I just need to fill them in with characters and not integers.
I have this so far:
char array[20][20];
srand(time(NULL));
for(int i=0;i<20;i++)
{
for(int j=0;j<20;j++) {
array[i][j]= ((rand() % 2) == 0) ? 'O' : 'X';
}
}
I don’t know if that formatted right because the code thing is being weird for me, but if I have this right. How exactly do I print it out for when I run it?
I can’t test it because I don’t know how to print it out :/
But I feel like I have it wrong anyway.
EDIT
Then I also need to know how to swap the multidimensional array vertically… still keeping the same values/grid setup, but basically just reflecting it vertically. Not horizontally though..
You have the generation part right. As for printing, use