Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function like C# Array.Copy() in the C language

Tags:

c

c#

I'm looking for a C function similar to the C# Array.Copy(). I found memcpy() only, but I need to copy from specific index too.

like image 996
deem Avatar asked Dec 21 '22 23:12

deem


1 Answers

If you have an array like this:

SomeType myArray[50];

And you want to copy elements indexed 19-29 (the 20th through 30th elements).

Then you do:

memcpy(dest, &myArray[19], 10 * sizeof(SomeType));

Note: this code-segment makes no provision for initializing myArray, or allocating memory to dest

like image 67
abelenky Avatar answered Jan 11 '23 23:01

abelenky