For some reason I am retarded at arrays and I can't figure out how to print a 2D array in C. I am randomly creating a 0 or 1 and then assigning a blank space for a 0 and a * for a 1. Then I am trying to print out the array (using spaces and stars) but I cannot get it to output correctly.
I would also like to get it to print out in a 20x20 grid. I'm not sure how to do that (I assume with the mod operator?).
As a disclaimer, I have searched this site for a while now and most of the examples are in C++. The C examples haven't helped me
Anyway, here is my code, and thanks in advance for any/all help!
char life [max][max];
char symbol, a, b;
int r, i, j;
/* assign random 0 or 1 and convert to " " or "*" for every array address */
srand(time(NULL));
for (i = 0; i < max; i++)
{
for (j = 0; j < max; j++)
{
r = rand()%2;
if (r == 0)
{
symbol = ' ';
}
else
{
symbol = '*';
}
a = symbol;
b = symbol;
printf ("%c", life[a][b]);
}
}
This post has been edited by ShotokanDeity: 23 October 2007 - 09:35 PM

New Topic/Question
Reply




MultiQuote




|