-
3D array
Anyone that's seen one of my previous posts over the past few days , most of that stuff has now been scrapped as I thought we needed to have an uninitialized array, but it turns out we don't.
anyway, so now I'm trying to declare this array but its throwing out an error that seems weird to me but I'm sure its simple. here's the array that's causing the error;
Code:
char array1[3][7][7] =
{
{
{'0','0','0','1','0','0','0'},
{'0','0','1','1','0','0','0'},
{'0','0','0','1','0','0','0'},
{'0','0','0','1','0','0','0'},
{'0','0','0','1','0','0','0'},
{'0','0','1','1','1','0','0'}
},
{
{'0','0','2','2','2','0','0'},
{'0','2','0','0','0','2','0'},
{'0','0','0','0','2','0','0'},
{'0','0','0','2','0','0','0'},
{'0','0','2','0','0','0','0'},
{'0','2','0','0','0','0','0'},
{'0','2','2','2','2','2','0'}
},
{
{'0','3','3','3','3','0','0'},
{'0','0','0','0','0','3','0'},
{'0','0','0','0','0','3','0'},
{'0','3','3','3','3','0','0'},
{'0','0','0','0','0','3','0'},
{'0','0','0','0','0','3','0'},
{'0','3','3','3','3','0','0'};
//populate(array1);
display(array1);
return 0;
and this is the error
ICA2.cpp:43: error: expected `}' before ‘;’ token
ICA2.cpp:43: error: expected `}' before ‘;’ token
(it shows twice)
thing is, there already is a ; before the } on line 43. is there meant to be one further up?
thanks in advance
ES
P.S I realise the populate function call is a comment, I've left that function in from a previous program in case I need it later
-
You're missing two } at the end. It's pretty easy to spot considering the indentation.
-
Is this syntax possible in C++? I thought you could only use two brackets. One opening one and one closing one. With only two it works for sure. You would just have for example
Code:
char array[2][2] = { '0', '1',
'1', '1'};
The newline is optional, you could put the four values in one line if you wanted, but it makes more sense like above. The result is the same in any case.
-
edit; added some variety because I'm bored. :]
You must not understand how brackets work if you can't figure that out. Study what I've written below very carefully, then look at your source, you'll see where you missed the brackets.
This is a 1D array;
Code:
int array[1] = {1};
int array[3] = {1,2,3};
This is a 2D array;
Code:
int array[2][2] = { {1,2}, {3,4} };
int array[3][3] = { {1,2,3}, {4,5,6}, {7,8,9} };
This is a 3D array;
Code:
int array[3][3][3] = { { {1,1,1}, {2,2,2}, {3,3,3} }, { {4,4,4}, {5,5,5}, {6,6,6} }, { {7,7,7}, {8,8,8}, {9,9,9} } };
int array[2][3][3] = { { {1,1,1}, {2,2,2}, {3,3,3} }, { {4,4,4}, {5,5,5}, {6,6,6} } };
int array[2][2][3] = { { {1,1,1}, {2,2,2} }, { {3,3,3}, {4,4,4} } };
int array[1][2][3] = { { {1,1,1}, {2,2,2} } };
I am explaining this too death, I'm going to get back to work.
-
*face palms* of course! I see it now, I knew it would be something simple/stupid
you'll have to forgive me, I'm not used to spotting these little errors yet, but I'm still learning.
Anyway, Thanks for the help
ES
-
Take care to indent properly. If you wish to continue over several rows, put each dimension's { on an extra tab or some spaces of indentation. Just like you would do for blocks. It makes it easy to spot mistakes.