View Single Post
Old 06-13-2006, 07:55 PM   #13 (permalink)
Manan
Registered User
 
Join Date: Jul 2005
Posts: 16
Manan is on a distinguished road
I've decided to use a template, because I have way too little time to actually do a totally random board generator. But I'm having another problem declaring 2d arrays.
Code:
if(randTemplate == 1)
	{ //If template 2 is chosen
		int buffer[9][9] = {

             {n[6],n[7],n[8], n[1],n[0],n[4], n[2],n[5],n[3] },
             {n[1],n[4],n[5], n[2],n[8],n[3], n[6],n[0],n[7] },
             {n[2],n[0],n[3], n[5],n[7],n[6], n[4],n[1],n[8] },

             {n[8],n[2],n[1], n[7],n[6],n[0], n[5],n[3],n[4] },
             {n[5],n[3],n[0], n[4],n[2],n[8], n[1],n[7],n[6] },
             {n[7],n[6],n[4], n[3],n[1],n[5], n[8],n[2],n[0] },

             {n[0],n[5],n[7], n[8],n[4],n[2], n[3],n[6],n[1] },
             {n[4],n[1],n[2], n[6],n[3],n[7], n[0],n[8],n[5] },
             {n[3],n[8],n[6], n[0],n[5],n[1], n[7],n[4],n[2] }
          };
}
The above segment of code works perfectly. However, I want to declare int buffer[][] outside the if statement. This is because, it is currently a local variable and I want to use it outside the if statement. Here is what I'm trying to do:
Code:
int buffer[9][9];
if(randTemplate == 1)
	{ //If template 2 is chosen
		buffer[][] = {

             {n[6],n[7],n[8], n[1],n[0],n[4], n[2],n[5],n[3] },
             {n[1],n[4],n[5], n[2],n[8],n[3], n[6],n[0],n[7] },
             {n[2],n[0],n[3], n[5],n[7],n[6], n[4],n[1],n[8] },

             {n[8],n[2],n[1], n[7],n[6],n[0], n[5],n[3],n[4] },
             {n[5],n[3],n[0], n[4],n[2],n[8], n[1],n[7],n[6] },
             {n[7],n[6],n[4], n[3],n[1],n[5], n[8],n[2],n[0] },

             {n[0],n[5],n[7], n[8],n[4],n[2], n[3],n[6],n[1] },
             {n[4],n[1],n[2], n[6],n[3],n[7], n[0],n[8],n[5] },
             {n[3],n[8],n[6], n[0],n[5],n[1], n[7],n[4],n[2] }
          };
}
I get about 50-60 errors when I do this. I've even tried getting rid of the [][], and I also tried making it [9][9], but it won't work. Help is greatly appreciated
Manan is offline   Reply With Quote