# totally stumped

• 08-22-2004
sand_man
totally stumped
why wont this complie?
Code:

int main()
{
typedef struct {
char block[4][4];
}BLOCK;
BLOCK L_block;
L_block.block =
{0,1,0,0,
0,1,0,0,
0,1,0,0,
0,1,0,0,};
}

• 08-22-2004
Salem
Because you're trying to do an assignment, not an initialisation.
• 08-22-2004
sand_man
hmm
so how do i assign values to an array in a structure?

nevermind. what you said made me realise what i was doing wrong :)
thanks salem.
[/edit]

[edit again]
there must be an easier way to do it than this right? the numbers arent sequential so i cant use a for loop
Code:

int main()
{
typedef struct blk{
char block[4][4];
}BLOCK;

BLOCK Lblock[4];

Lblock[0].block[0][0] = 0;
Lblock[0].block[0][1] = 1;
Lblock[0].block[0][2] = 0;
...//etc
return 0;
}

[/edit again]
• 08-22-2004
Salem
Code:

BLOCK Lblock[4] = { 0 };
for ( i = 0 ; i < 4 ; i++ ) Lblock[i].block[0][1] = 1;

• 08-22-2004
Thantos
Code:

int main(void)
{
typedef struct {
char block[4][4];
}BLOCK;
BLOCK L_block =
{0,1,0,0,
0,1,0,0,
0,1,0,0,
0,1,0,0,};

return 0;
}

Wouldn't that be easier?
• 08-22-2004
Dave_Sinkula
Another option, since the array is within a structure, is to use structure assignment.
Code:

struct sBlock
{
char block[4][4];
};

static const struct sBlock DefaultBlock =
{
{
{0,1,0,0},
{0,1,0,0},
{0,1,0,0},
{0,1,0,0},
},
};

int main(void)
{
struct sBlock myblock = {0}; /* initialization */
/* ... */
myblock = DefaultBlock; /* assignment */
return 0;
}

• 08-22-2004
sand_man
thankyou dave