A simple C/C++ question for all you brainiacs.

NuclearNed

Raconteur
May 18, 2001
7,849
339
126
Suppose I have an integer array, defined thus:

int nPattern[8][3];

It seems like there is an easy way to initialize this array, like so:

nPattern = {{0,0,0}, {1,0,0}, {0,1,0}, {0,0,1}, {1,1,0}, {1,0,1}, {0,1,1}, {1,1,1}};

But this doesn't work (syntax error}. I've used so many different languages lately that I've forgotten how to do this in my "native" language. Is there an easy way to do this?

Help??!?!?!???!!!
 

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
Originally posted by: NuclearNed
Suppose I have an integer array, defined thus:

int nPattern[8][3];

It seems like there is an easy way to initialize this array, like so:

nPattern = {{0,0,0}, {1,0,0}, {0,1,0}, {0,0,1}, {1,1,0}, {1,0,1}, {0,1,1}, {1,1,1}};

But this doesn't work (syntax error}. I've used so many different languages lately that I've forgotten how to do this in my "native" language. Is there an easy way to do this?

Help??!?!?!???!!!


Umm, i just just just started and dont know everything about arrays, but try using a bracket like () instead
 

darktubbly

Senior member
Aug 19, 2002
595
0
0
If I remember correctly, you can only initialize arrays like that upon declaration. So you would have to do:

int nPattern[8][3] = {{0,0,0}, {1,0,0}, {0,1,0}, {0,0,1}, {1,1,0}, {1,0,1}, {0,1,1}, {1,1,1}};
 

Glavinsolo

Platinum Member
Sep 2, 2004
2,946
0
0
yes , int nPattern[8][3]= {{0,0,0}, {1,0,0}, {0,1,0}, {0,0,1}, {1,1,0}, {1,0,1}, {0,1,1}, {1,1,1}};

or int nPattern[][3]= {{0,0,0}, {1,0,0}, {0,1,0}, {0,0,1}, {1,1,0}, {1,0,1}, {0,1,1}, {1,1,1}};

BTW

Looks like an octal bit pattern...

but I thought the order was

int nPattern= {{0,0,0},
{0,0,1},
{0,1,0},
{0,1,1},
{1,0,0},
{1,0,1},
{1,1,0},
{1,1,1}}

you can also use a pointer
 

NuclearNed

Raconteur
May 18, 2001
7,849
339
126
Originally posted by: Glavinsolo
yes , int nPattern[8][3]= {{0,0,0}, {1,0,0}, {0,1,0}, {0,0,1}, {1,1,0}, {1,0,1}, {0,1,1}, {1,1,1}};

or int nPattern[][3]= {{0,0,0}, {1,0,0}, {0,1,0}, {0,0,1}, {1,1,0}, {1,0,1}, {0,1,1}, {1,1,1}};

BTW

Looks like an octal bit pattern...

but I thought the order was

int nPattern= {{0,0,0},
{0,0,1},
{0,1,0},
{0,1,1},
{1,0,0},
{1,0,1},
{1,1,0},
{1,1,1}}

you can also use a pointer

The pattern is just all binary combinations of 3 bits, not necessarily an octal pattern.

Thanks to all for the help - I'm getting a little bit of play time in at work, and I'm trying to implement a graphical algorithm I read about in Wired several months ago. Maybe when I get the code done I'll post it so everyone can see the coolness.