✅memccpy
- The memccpy() function copies no more than
Size
bytes from memmory area Src
to memory area Dst
, stopping when the character Val
is found.
if the memory areas overlap, the results are undefined.
- copy string until character found
Src
의 값들을 Size
만큼 복사, 복사하는 과정에서 Val
을 찾게되면 중단.
💾함수 원형
void *memccpy(void *Dst, const void *Src, int Val, size_t Size)
💻Parameters
void *Dst
: 복사될 지점
const void *Src
: 복사할 내용
int Val
: 복사를 멈출 문자
size_t Size
: 복사할 데이터의 바이트 수
💻Return value
Val
을 찾으면 Val
다음 주소값을 반환
Src
의 값에서 Size
만큼 중 Val
을 찾지 못하면 Null
을 반환
💾함수 구현
#include "libft.h"
void* ft_memccpy(void* dst, const void* src, int c, size_t n)
{
unsigned char* tmp;
unsigned char* str;
size_t i;
tmp = (unsigned char*)dst;
str = (unsigned char*)src;
i = 0;
while (i < n)
{
tmp[i] = str[i];
if (str[i] == (unsigned char)c)
return ((void*)dst + i + 1);
i++;
}
return (0);
}