Array question


In the code I’m building, I have the need to assign one array to another and have gone about the task as follows.

Is there a better way?

(Array_1 and Array_2 are both globally declared as integers.)

 for (int x = 0; x < 7; x++) {

     Array_1[x] = Array_2[x];




memcpy(Array_1, Array_2, sizeof(Array_2) ); // for sizeof() choose the smaller one in case

But a counter question, why do you want to copy the whole array?

Thanks ArthurD works perfectly and the link saved me from asking extra questions.

Hi septillion.

In my code each element of Array_1 points to a digit of an LED display.

Array_2 is one of five arrays which stores information to be displayed based on the presses of a button. The information comes from a GPS module.

Using arrays like this is wasteful of memory but I found it enabled me to separate the functions of: - receiving, processing and recording from the serial stream. - Selecting what is displayed. - display refresh

A less space consuming way would be to store the state of the 7 led (plus the dot?) in a single byte.

Not so trivial to manipulate, but very easy to copy. ;)

Or, just point to the right array at the right time instead of coping it.