memcpy with startIndex?

soloasylum picture soloasylum · Jul 22, 2009 · Viewed 71.8k times · Source

I wish to copy content of specific length from one buffer to another from a specific starting point. I checked memcpy() but it takes only the length of content to be copied while I want to specify the starting index too.

Is there any function which can do this or is there any good approach to do it with the existing memcpy function?

Answer

Goz picture Goz · Jul 22, 2009

I always prefer the syntax

memcpy( &dst[dstIdx], &src[srcIdx], numElementsToCopy * sizeof( Element ) );