memcpy with startIndex?

后端 未结 9 1249
星月不相逢
星月不相逢 2020-12-24 11:31

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

9条回答
  •  死守一世寂寞
    2020-12-24 11:48

    An index is not required because you can simply update the source pointer by the specified number of bytes. The following wrapper should do the trick

    void* memcpy_index(void *s1, const void *s2, size_t index, size_t n) {
      s2 = ((char*)s2)+index;
      return memcpy(s1, s2,n);
    }
    

提交回复
热议问题