在基于C语言开发时,容易将memccpy和memcpy弄混, memccpy的函数原型:
void *memccpy(void * restrict dest, const void * restrict src, int c, size_t count);
参数说明,
dest - pointer to the object to copy to
src - pointer to the object to copy from
c - terminating character, converted to unsigned char at first
count - number of characters to copy
这里容易出现理解偏差的是参数 c,“terminating character, converted to unsigned char at first” 也就是参数会转化为unsigned char 也就是需要传入的是单个字符,当检测到传入的src 中字符与"c"匹配时,停止copy,退出.
参考链接:
https://en.cppreference.com/w/c/string/byte/memccpy