본문 바로가기

42Seoul/libft36

ft_substr substr? //원 함수 없음 char *ft_substr(char const *s, unsigned int start, size_t len); 구현해야할 함수 기능 : Allocates (with malloc(3)) and returns a substring from the string ’s’. The substring begins at index ’start’ and is of maximum size ’len’. 해석 및 부연설명 : 문자열 s에서 원하는 부분만큼(start부터 len만큼) 잘라 반환한다. 지정된 반환값은 부분 문자열이며 할당 실패 시에는 NULL을 반환한다. ex) charstr[] = "abcdefgehijk"; char*substr = ft_substr(str, 5, 3); p.. 2023. 2. 16.
ft_strrchr strchr? #include char *strrchr(const char *s, int c); Linux manpage description : The strrchr() function returns a pointer to the last occurrence of the character c in the string s. 해석 및 부연설명 : 문자열 s에서 문자 c를 탐색하여 가장 마지막으로 발견된 곳의 위치를 포인터로 반환하는 함수다. 찾지 못한 경우 NULL을 반환한다. ex) charstr[] = "abcdefgehijk"; charc = 'e'; printf("%s\n", strrchr(str, c)); 코드 실행 결과 ehijk 그냥 strchr의 reverse버전 함수다. 의문점 및 생각해볼.. 2023. 2. 16.
ft_strnstr strnstr? #include char *strnstr(const char *big, const char *little, size_t len); Linux manpage description : The strnstr() function locates the first occurrence of the null-terminated string little in the string big, where not more than len characters are searched. Characters that appear after a ‘\0’ character are not searched.. 해석 및 부연설명 : strchr에서 한발 더 나아가 문자열을 검색하는 함수이다. little에 해당하는 문자열이 bi.. 2023. 2. 16.
ft_strdup strdup? #include char *strdup(const char *s); Linux manpage description : The strdup() function returns a pointer to a new string which is a duplicate of the string s. Memory for the new string is obtained with malloc(3), and can be freed with free(3). 해석 및 부연설명 : 새로 메모리를 할당하여 문자열 s를 복붙한 후 시작주소를 반환한다. malloc과 strcpy가 합쳐진 함수라고 보면 된다. ex) charstr[] = "abcdefg"; char*new; new = strdup(str); printf(.. 2023. 2. 16.