Jump to content

Recommended Posts

Posted

hello,

i have a c question :

i have a global array :                  unsigned char test[2][2];

each time a certain button is pressed, i want to reset my array to the default array

{{1,2},{2,2}}

(this is just a 2*2 example, the array in my code is much bigger).

int this case the following line doesn't work :

test = {{1,2},{2,2}};

i don't want to use a loop for this !

do i have to use pointers ?

thanx

jeb

Posted

hello,

no the brackets solution doesn't work !

the problem is maybe that i want to redefine the values of an array which has already been defined.

should i use pointers ?

for example if i have a global variable :

////  unsigned char test [3];

the use of this, in a function :

////  test = {8, 8, 8};

gives :

syntax error: token -> '{' ; column 9

thanx in advance!

Posted

Hello,

I think that this way of intializing arrays is only valid when it's used while defining the variable. I don't think it's allowed to be used as this in the body of a function.

You could indeed use a pointer instead, have a collection of the constant tables as you shown and have the pointer to point on one of the constant tables.

Othewise, you can also define constant tables and use a memcpy like function to copy the constant table within your array.

Best regards,

Lall

Posted

I think that this way of initializing arrays is only valid when it's used while defining the variable. I don't think it's allowed to be used as this in the body of a function.

I had a feeling that was it, but I didn't have the confidence to say it heheheh

Hey jeb what are you putting in this array? There might be a quick way, depending on what is going in there...

  • 7 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...