-
💡 [C언어] memccpy 함수 설명 및 예시| 프로그래밍 분야/C 2021. 5. 4. 15:27
💡 man memccpy
NAME
memccpy -- copy string until character found
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <string.h>
void *
memccpy(void *restrict dst, const void *restrict src, int c, size_t n);
DESCRIPTION
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.
The source and destination strings should not overlap, as the behavior is undefined.
SEE ALSO
bcopy(3), memcpy(3), memmove(3), strcpy(3)
HISTORY
The memccpy() function first appeared in 4.4BSD.memccpy() 함수는 string.h 에 정의된 함수로, memcpy() 함수와 동일한 기능을 하나 파라미터가 하나 추가되었다.
[C언어] memcpy 함수 설명 및 다양한 예시
💡 man memcpy NAME memcpy -- copy memory area LIBRARY Standard C Library (libc, -lc) SYNOPSIS #include void * memcpy(void *restrict dst,..
meoru-tech.tistory.com
추가된 파라미터는 int c로, 해당하는 값이 src에 있으면 가장 먼저 나오는 c 값까지만 복사를 해준다.
그리고 c 값 다음의 주솟값을 리턴한다.
c 에 해당하는 값이 src에 없으면, 지정해준 바이트 크기 n 만큼 복사한 후 널 포인터를 리턴한다.
void *memccpy(void *restrict dst, const void *restrict src, int c, size_t n);
dst : 복사 대상 주소
src : 복사 소스 주소
c : 복사를 멈출 플래그값 (int형이지만 'a'와 같이 작은 따옴표로 문자도 가능)
n : 복사할 바이트 크기
size_t 에 관한 포스팅)
[C/C++] size_t 자료형의 정의
size_t 아래는 C99의 원문이다. size_t can store the maximum size of a theoretically possible object of any type. 즉, 32비트 환경에서는 32비트, 64비트 환경에서는 64비트의 unsigned 변수로써 다음과 같..
meoru-tech.tistory.com
💡 테스트케이스