📌strnstr
✔️ 함수 프로토타입
char *strnstr(const char *haystack, const char *needle, size_t len);
✔️ 함수의 역할 : haystack의 len 길이 내에서 needle이 있는 지 찾는다.
✔️함수 반환값
✏️ haystack 안에 needle이 없는 경우 : NULL 반환
✏️ needle이 빈 문자열인 경우 : haystack 반환
✏️haystack 안에 needle이 존재할 경우 : needle이 처음 발견된 곳의 첫번째 문자 위치 (포인터)
✔️ man page에 나온 설명!
👀 Description
The strnstr() function locates the first occurrence of the null-terminated string needle in the string haystack, where not more than len characters are searched. Characters that appear after a ‘\0’ character are not searched. Since the strnstr() function is a FreeBSD specific API, it should only be used when portability is not a concern.
➿해석 : strnstr은 문자열 haystack에서 첫번째로 나타나는 널로 종료되는 문자열 needle의 위치를 찾는다. haystack은 len 길이 만큼만 찾는다. strnstr은 freeBSD specific API이기 때문에, portability가 고려되지 않을 때만 사용한다.
👀 Return Values
If needle is an empty string, haystack is returned; if needle occurs nowhere in haystack, NULL is returned; otherwise a pointer to the first character of the first occurrence of needle is returned.
➿해석 : 만약 needle이 빈 문자열이라면 haystack이 반환된다.; 만약 needle이 haystack에서 발견되지 않으면 NULL이 반환된다; 그렇지 않으면 needle이 처음 발견된 곳의 첫 character를 가리키는 포인터가 반환된다.
freeBSD란 유닉스 계열 운영체제를 말한다. freeBSD specific API란 말은 strnstr함수는 운영체제에 specific하므로 다른 운영체제에 이식할 때는 쓰지 않는다는 뜻이다.
'🐰42서울 > libft' 카테고리의 다른 글
[42서울] libft 정리 : ft_strlen, ft_strlcpy, ft_strlcat 구현 (0) | 2022.02.07 |
---|---|
[42서울] libft 정리 : ft_toupper, ft_tolower 구현 (0) | 2022.01.14 |
[42서울] libft 정리 : ft_isalpha, ft_isdigit, ft_isalnum, ft_isascii, ft_isprint 구현 (0) | 2022.01.13 |
[42서울] libft 정리: strdup (0) | 2022.01.05 |
[42서울] libft 정리: calloc (0) | 2022.01.04 |