QUESTION QUICKLY: how save an array to another array

STR3 [0] = lectura2 [5]; //manuf
STR3 [1] = lectura2 [6]; //manuf
STR3 [2] = lectura2 [7]; //manuf

how to do the same but in only one line of code???????

thanks

Post full code, in code tags <>

strlcpy() or memcpy(), what data type are the arrays?

bytes !!!

Drogon:
bytes !!!

That makes it easy. Use memcpy() to copy all the bytes. Use strlcpy() if you want the copy to stop when a NULL is found.

memcpy() copy all the bytes

I do not want to copy all bytes only the bytes that interest me from the array.

get the value of x,y,z position of array 1 and copy it into array 2 in the position a,b,c

Drogon:
memcpy() copy all the bytes

I do not want to copy all bytes only the bytes that interest me from the array.

get the value of x,y,z position of array 1 and copy it into array 2 in the position a,b,c

array2[a] = array1[x];
array2[b] = array1[y];

etc etc etc though this does sound to me like an XY problem.

there is nothing to be able to do something like

array2[a,b] = array1[x,y];

to do everything at once and one line
and that works?

Drogon:
memcpy() copy all the bytes
I do not want to copy all bytes only the bytes that interest me from the array.

It’s always good to define your problem clearly and completely in your first post.

memcpy() copies as many bytes as you want.

memcpy(array2+a, array1+x, 3);

EDIT: assumes desired bytes are consecutive.

Drogon:
there is nothing to be able to do something like

array2[a,b] = array1[x,y];

to do everything at once and one line
and that works?

Why are you so concerned about doing it in one line?

Drogon:
there is nothing to be able to do something like

array2[a,b] = array1[x,y];

to do everything at once and one line
and that works?

In APL yes but not in C or C++ .

Another one-liner ;D

array2[a] = array1[x]; array2[b] = array1[y]; array2[c] = array1[z];

hahahahahahha

it does not help me :grinning: :grinning: :grinning: :grinning: :grinning:

I have a lot of cases xd

Drogon:
I have a lot of cases xd

Maybe if you could be more specific we could help you find a compact way of doing the copy but in the abstract way you have presented the problem you can expect little further from us.

strncpy() with an n

lastchancename:
strncpy() with an n

I don't think so unless the OP is working only with cstring and nothing in the thread so far indicates he is and the whole tone of the thread implies he is not.

Very true... any embedded nulls would toss my suggestion.
So back to memcpy((

Use memcpy, or one of its variants. There is a link to the documentation for AVR libc in point 13 of the sticky post on this sub.

PaulMurrayCbr:
Use memcpy, or one of its variants. There is a link to the documentation for AVR libc in point 13 of the sticky post on this sub.

This has been suggested several times but it has been rejected by the OP because his source and destination array elements are not necessarily contiguous. I still think this is an XY problem.

stowite:
This has been suggested several times but it has been rejected by the OP because his source and destination array elements are not necessarily contiguous. I still think this is an XY problem.

Huh

I do not want to copy all bytes only the bytes that interest me from the array.

OP does not understand arrays. Or possibly memory. He got his answer

memcpy(array2+a, array1+x, 3);

(which should probably be

memcpy(array2+a, array1+x, 3 * sizeof(*array1));

)

But doesn't understand it.