Jump to content

redifining an array


jeb
 Share

Recommended Posts

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

  • 7 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...