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
I always prefer the syntax
memcpy( &dst[dstIdx], &src[srcIdx], numElementsToCopy * sizeof( Element ) );
You could have a function like below.
template<typename T>
T* memcopy_index(T* dst,T* src,unsigned int index, unsigned int element_count)
{
return (T*)memcpy(dst,src + index, element_count * sizeof(T));
}
It can be used as below:
int src[]={0,1,2,3,4,5,6};
int dst[15];
memcopy_index(dst,src,2,5); //copy 5 elements from index 2
You have to make sure that destination buffer has enough room to copy the elements.
Just add the offset you want to the address of the buffer.
char abuff[100], bbuff[100];
....
memcpy( bbuff, abuff + 5, 10 );
This copies 10 bytes starting at abuff[5] to bbuff.