• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

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

NuclearNed

Raconteur
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??!?!?!???!!!
 
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
 
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}};
 
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
 
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.

 
Back
Top