struct boardType
{
    int boardNumber[8][7][7];
    int numberOfBoards;
};

//note: int main() is assumed as standard "bloodshed DEV-C++" compiler 

boardType totalBoards;
totalBoards.numberOfBoards = 8;
totalBoards.boardNumber[0] = {{0,0,0,0,0,0,0},
                              {6,6,6,1,6,6,1},
                              {6,6,6,6,6,6,1},
                              {6,6,6,6,6,6,1},
                              {6,6,6,6,6,6,1},
                              {6,6,6,6,6,6,1},
                              {5,5,5,5,5,5,5}};

expected primary-expression before '{' token
expected ';' before '{' token

Above shows the script I am trying to make work. the quote is the error that is built when first row compiles. Im trying to see where but my ignorance and in ability to memorize array syntax is truely showing

EDIT: what I am trying to do is store 8 boards that are 7x7 each. I don't wish to use vectors because I am trying to understand arrays. Vectors come later :P

3 dimentional arrays or a one dimentional struct that stores a 7x7 array. Im using structs to store the full list of arrays.

struct boardType
{
    int boardNumber[7][7];
};
     boardType currentBoard[8];
    currentBoard[0].boardNumber = {{0,0,0,0,0,0,0},
                              {6,6,6,1,6,6,1},
                              {6,6,6,6,6,6,1},
                              {6,6,6,6,6,6,1},
                              {6,6,6,6,6,6,1},
                              {6,6,6,6,6,6,1},
                              {5,5,5,5,5,5,5}};

Recommended Answers

All 4 Replies

You can only initialise arrays, you can't assign them on-mass like you're trying to do.

boardType totalBoards = {
                              {
                              {0,0,0,0,0,0,0},
                              {6,6,6,1,6,6,1},
                              {6,6,6,6,6,6,1},
                              {6,6,6,6,6,6,1},
                              {6,6,6,6,6,6,1},
                              {6,6,6,6,6,6,1},
                              {5,5,5,5,5,5,5}
                              },
                              8
};

o.0 oh I see :( that's too bad

so, what can I do? I know the values of each element of all the boards, and I want to store them to a '.dat' file so that they can be loaded when the app runs. Is a strucure not a good way to go? Or should I just script them in and not worry about reading from a file (really it will be a small app, probably no more than 1000 lines)I guess I could initialize all 8 boards at once and just store them as different names I guess.
what about something like this?

boardType currentBoard[8] = {
       {{0,0,0,0,0,0,0},{6,6,6,1,6,6,1},{6,6,6,6,6,6,1},{6,6,6,6,6,6,1},{6,6,6,6,6,6,1},{6,6,6,6,6,6,1},{5,5,5,5,5,5,5}},
       {{0,0,0,0,0,0,0},{6,6,6,1,6,6,1},{6,6,6,4,6,6,1},{6,6,6,6,6,6,1},{6,6,6,6,6,6,1},{6,6,6,6,6,6,1},{5,5,5,5,5,5,5}},
       {{0,0,0,0,0,0,0},{6,6,6,1,6,6,1},{6,6,6,4,6,6,1},{6,6,6,1,6,6,1},{6,6,6,6,6,6,1},{6,6,6,6,6,6,1},{5,5,5,5,5,5,5}},
       {{0,0,0,0,0,0,0},{6,6,6,1,6,6,1},{6,6,6,4,6,6,1},{6,6,6,1,3,6,1},{6,6,6,6,6,6,1},{6,6,6,6,6,6,1},{5,5,5,5,5,5,5}},
       {{0,0,0,0,0,0,0},{6,6,6,1,6,6,1},{6,6,6,4,6,6,1},{6,6,2,1,3,6,1},{6,6,6,6,6,6,1},{6,6,6,6,6,6,1},{5,5,5,5,5,5,5}},
       {{0,0,0,0,0,0,0},{6,6,6,1,6,6,1},{6,6,6,4,6,6,1},{6,6,2,1,3,6,1},{6,6,6,1,6,6,1},{6,6,6,6,6,6,1},{5,5,5,5,5,5,5}},
       {{0,0,0,0,0,0,0},{6,6,6,1,6,6,1},{6,6,6,4,6,6,1},{6,6,2,1,3,6,1},{6,6,6,1,6,6,1},{6,6,6,6,2,6,1},{5,5,5,5,5,5,5}},
       {{0,0,0,0,0,0,0},{6,6,6,1,6,6,1},{6,6,6,4,6,6,1},{6,6,2,1,3,6,1},{6,6,6,1,6,6,1},{6,6,3,6,2,6,1},{5,5,5,5,5,5,5}}
       };

any advice here?

I tried to give it one more edit but no luck..
so anywho,

I temporarily solved the problem by initializing a const array of

const int hangmanBoard[8][7][7] = {
{{0,0,0,0,0,0,0},{6,6,6,1,6,6,1},{6,6,6,6,6,6,1},{6,6,6,6,6,6,1},{6,6,6,6,6,6,1},{6,6,6,6,6,6,1},{5,5,5,5,5,5,5}},
{{0,0,0,0,0,0,0},{6,6,6,1,6,6,1},{6,6,6,4,6,6,1},{6,6,6,6,6,6,1},{6,6,6,6,6,6,1},{6,6,6,6,6,6,1},{5,5,5,5,5,5,5}},
{{0,0,0,0,0,0,0},{6,6,6,1,6,6,1},{6,6,6,4,6,6,1},{6,6,6,1,6,6,1},{6,6,6,6,6,6,1},{6,6,6,6,6,6,1},{5,5,5,5,5,5,5}},
{{0,0,0,0,0,0,0},{6,6,6,1,6,6,1},{6,6,6,4,6,6,1},{6,6,6,1,3,6,1},{6,6,6,6,6,6,1},{6,6,6,6,6,6,1},{5,5,5,5,5,5,5}},
{{0,0,0,0,0,0,0},{6,6,6,1,6,6,1},{6,6,6,4,6,6,1},{6,6,2,1,3,6,1},{6,6,6,6,6,6,1},{6,6,6,6,6,6,1},{5,5,5,5,5,5,5}},
{{0,0,0,0,0,0,0},{6,6,6,1,6,6,1},{6,6,6,4,6,6,1},{6,6,2,1,3,6,1},{6,6,6,1,6,6,1},{6,6,6,6,6,6,1},{5,5,5,5,5,5,5}},
{{0,0,0,0,0,0,0},{6,6,6,1,6,6,1},{6,6,6,4,6,6,1},{6,6,2,1,3,6,1},{6,6,6,1,6,6,1},{6,6,6,6,2,6,1},{5,5,5,5,5,5,5}},
{{0,0,0,0,0,0,0},{6,6,6,1,6,6,1},{6,6,6,4,6,6,1},{6,6,2,1,3,6,1},{6,6,6,1,6,6,1},{6,6,3,6,2,6,1},{5,5,5,5,5,5,5}}
};

and will use pieces of it as I need it. The array does it's purpose, but still would like to write it to a file and read it from a file in the end.

problem is not truely solved to my specifications unless someone could help guide my noobyness in the right direction with proper code design and array/object manipulation
(each board is a numeric representation of a graphic that will be printed on the screen) -- hangman boards :P

Sure, there's nothing to stop you using some loops, to read a bunch of values out of a file, and assign to your arrays one element at a time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.