The memccpy() function copies bytes from string src to string dst.
If the character c (as converted to an unsigned char) occurs in the string src, the copy stops and a pointer to the byte after the copy of c in the string dst is returned. Otherwise, n bytes are copied, and a NULL pointer is returned.
변수명 | 설명 |
---|---|
dst | 복사되는 메모리의 첫번째 주소 |
src | 복사할 메모리의 첫번째 주소 |
c | src에서 만나면 복사를 중단할 char (unsigned char) |
n | 복사할 길이 (byte 단위) |
성공 : 복사가 끝난 후 dst의 다음 메모리 주소.
실패 : NULL
void *memccpy(void *dst, const void *src, int c, size_t n)
{
size_t i;
unsigned char *dst_ptr;
unsigned char *src_ptr;
unsigned char find;
i = 0;
find = c;
dst_ptr = dst;
src_ptr = (unsigned char *)src;
while (i < n)
{
dst_ptr[i] = src_ptr[i];
if (src_ptr[i] == find)
return (dst + i + 1);
i++;
}
return (0);
}