42 March - 1. Libft

수현·2023년 3월 13일
0

42Seoul

목록 보기
1/8

📒 Technical consideration

when

  • 23.03.13 월 21:20 ~ 22:50
  • 23.03.23 목 15:00 ~ 18:00 / 19:30 ~ 23:00
  • 23.03.25 토 15:30 ~ 18:00 / 21:00 ~ 24:00
  • 23.03.26 일 00:00 ~ 04:00 / 10:00 ~ 16:00
  • 23.03.27 월 21:00 ~ 24:30
  • 23.04.02 일 13:30 ~ 02:00
  • 23.04.05 수 20:00 ~ 02:00 (평가)
  • 23.04.07 금 11:00 ~ 16:00 (평가)
내용
프로그램 이름libft.a
제출 파일ft_*.c, libft.h, Makefile
MakefileNAME, all, clean, fclean, re
외부 함수malloc

📌 주의사항

  • norm error 금지

  • segmetation fault, bus error, double free 금지

  • heap에 동적 할당된 메모리 해제 (메모리 누수 방지)

  • Makefile

    • -Wall -Wextra -Werror 플래그 지정
    • relink 금지 (다시 make했을 때 재실행 금지)
    • $(NAME), all, clean, fclean, re 규칙 포함
  • 전역 변수 사용 금지

    • 본 기능을 구현하기 위한 sub function 정의 시 static으로 정의
      → 정의되지 않은 참조 막기 위해
  • library를 만들기 위해서 ar command 사용

    • libtool 사용 금지
  • 함수 구현 시 앞에 ft_ 붙이기

  • restrict 키워드는 C99에서 정의되므로 사용 금지

📒 Libc functions

📕 1. ft_isalpha

1) isalpha 정의

  • header file
    • #include <ctype.h>
  • funtion prototype
    • int isalpha(int c);
  • description
    • 알파벳 판별 함수
    • isupper(c) || islower(c)와 동일
  • return value
    • 알파벳일 경우 : true 반환
    • 아닐 경우 : false 반환

2) 구현

int	ft_isalpha(int c)
{
	if ((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')))
		return (1);
	return (0);
}

📖 참고 📖 c가 int형인 이유

  • 대문자와 소문자 이외에 EOF 값 또는 unsigned char 값 표현해야함
  • char형은 -128 ~ 127 범위이므로 EOF(-1) 또는 unsigned char 처리 불가능

📕 2. ft_isdigit

1) isdigit 정의

  • header file
    • #include <ctype.h>
  • funtion prototype
    • int isdigit(int c);
  • description
    • 숫자 판별 함수
  • return value
    • 숫자일 경우 : true 반환
    • 아닐 경우 : false 반환

2) 구현

int	ft_isdigit(int c)
{
	if ('0' <= c && c <= '9')
		return (1);
	return (0);
}

📕 3. ft_isalnum

1) isalnum 정의

  • header file
    • #include <ctype.h>
  • funtion prototype
    • int isalnum(int c);
  • description
    • isalpha(c) || isdigit(c)와 동일
  • return value
    • 알파벳이거나 숫자일 경우 : true 반환
    • 아닐 경우 : false 반환

2) 구현

int	ft_isalnum(int c)
{
	if (('0' <= c && c <= '9')
		|| (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')))
		return (1);
	return (0);
}

📕 4. ft_isascii

1) isascii 정의

  • header file
    • #include <ctype.h>
  • funtion prototype
    • int isascii(int c);
  • description
    • ASCII 문자 집합에 맞는 7bit unsigned char인지 판별 함수
    • ASCII 코드 범위 : 0 ~ 127
  • return value
    • ASCII코드 범위 내일 경우 : true 반환
    • 아닐 경우 : false 반환

2) 구현

int	ft_isascii(int c)
{
	if (0 <= c && c <= 127)
		return (1);
	else
		return (0);
}

📕 5. ft_isprint

1) isprint 정의

  • header file
    • #include <ctype.h>
  • funtion prototype
    • int isprint(int c);
  • description
    • space(공백) 포함하여 출력할 수 있는 문자열인지 판별 함수
    • printable ASCII 범위 : 32 ~ 126
    • 아스키코드 127 : Delete
  • return value
    • 출력할 수 있는 문자일 경우 : true 반환
    • 아닐 경우 : false 반환

2) 구현

int	ft_isprint(int c)
{
	if (32 <= c && c <= 126)
		return (1);
	return (0);
}

📕 6. ft_strlen

1) strlen 정의

  • header file
    • #include <string.h>
  • funtion prototype
    • size_t strlen(const char *s);
  • description
    • 문자열 길이 반환 함수
    • null byte 제외하고 길이 계산
  • return value
    • string size 반환

2) 구현

#include "libft.h"

size_t	ft_strlen(const char *s)
{
	size_t	i;

	i = 0;
	while (*(s + i) != '\0')
		i++;
	return (i);
}

📖 참고 📖 size_t

  • 개념
    • c언어에서 임의의 객체가 가질 수 있는 최대 크기
    • 부호 없는 정수와 동일 (unsigned int)
    • sizeof 연산자의 반환 타입으로 사용됨
  • 사용 이유
    • 안전한 크기 타입을 제공하기 위해 사용
    • 시스템에서 주소 지정이 가능한 메모리 영역과 일치하는 크기를 선언하여 이식 가능한 방법을 제공할 목적
  • 출력
    • %zu 지정자 사용
    • %u, %lu 지정자 대체 가능
    • 출력 시 잘못 된 형식 지정자를 선택하며 예상치 못한 값 출력됨
  • 참고 사이트

📖 참고 📖 const

  • 개념
    • 변수를 선언할 때 변수의 데이터형 앞에 const 키워드를 지정하면 변경 불가능
    • 상수와 다르게 변수이기에 메모리에 할당이 되며, 단순 값을 변경 못하게함
    • 변수처럼 값 초기화 필요
  • 사용 이유
    • 전달 받은 내용을 바꾸지 않을 목적
    • 값 변경시 형 변환을 사용 가능
  • 참고 사이트

📖 참고 📖 char const vs const char

  • 개념
    • const char 타입의 포인터로 같은 의미
    • 포인터는 가리키는 메모리의 내용이 변경될 수 없음을 나타내기 위해 사용
    • const 키워드는 변수 & 포인터 모두 수정 가능
  • 차이점
    • char const * : char 타입을 가리키는 포인터의 값을 변경할 수 없는 것 (함수 내에서 해당 포인터 수정 가능)
    • const char * : 포인터를 가리키는 값이 변경될 수 없는 char 타입 (함수 내에서 해당 포인터 수정x)

📕 7. ft_memset

1) memset 정의

  • header file
    • #include <string.h>
  • funtion prototype
    • void memset(void s, int c, size_t n);
  • description
    • 메모리 주소 s부터 n 바이트만큼 c로 대체하는 함수
  • return value
    • memory 시작주소 포인터 s반환

2) 구현

#include "libft.h"

void	*ft_memset(void *b, int c, size_t len)
{
	unsigned char	*mem;
	unsigned char	value;

	mem = (unsigned char *)b;
	value = (unsigned char)c;
	while (len-- > 0)
		*mem++ = value;
	return (b);
}

// Main Example
int  intarr[10];
char chararr[10];

memset(intarr, 0, sizeof(intarr));
//memset(intarr, 0, sizeof(int) * 10);
memset(chararr, 'A', sizeof(chararr));
// intarr == '0 0 0 0 0 ...'
// chararr == "AAAAA..."

📖 참고 📖 void, unsigned char 포인터 캐스팅 이유

  • void 포인터 연산은 호환성을 위해 사용하지 않음
  • 메모리를 1바이트씩 접근하려면 unsigned char* 사용
  • 포인터는 주솟값이라 부호를 쓰지 않음

📖 참고 📖 int를 unsigend char로 바꿔야 하는 이유

  • 시스템에 따라서 문자가 1/2/4바이트일 수도 있는데, 문자를 1바이트로 가정하고 char/unsigned char로 사용할 경우 문자를 2/4바이트로 정의해야하는 시스템에서 사용 불가
  • c 값을 unsinged char 로 변환되어 1바이트의 메모리에 값을 집어넣어서 사용
  • 참고 사이트

📕 8. ft_bzero

1) bzero 정의

  • header file
    • #include <string.h>
  • funtion prototype
    • void bzero(void *s, size_t n);
  • description
    • 메모리 주소 s부터 n 바이트만큼 0으로 초기화하는 함수
  • return value
    • 없음

2) 구현

#include "libft.h"

void	ft_bzero(void *s, size_t n)
{
	unsigned char	*b;

	b = (unsigned char *)s;
	while (n-- > 0)
		*b++ = 0;
}

📕 9. ft_memcpy

1) memcpy 정의

  • header file
    • #include <string.h>
  • funtion prototype
    • void memcpy(void dest, const void *src, size_t n);
  • description
    • 메모리 주소 src 부터 n 바이트만큼 dest에 복사
    • dest와 src 메모리가 중첩될 경우 memmove 사용해야함
    • dest와 src 널인 경우 처리
    • strcpy( )와의 차이점 : null을 따로 확인하지x
  • return value
    • copy 성공시 : dest 포인터 반환
    • copy 실패시 : null 반환

2) 구현

#include "libft.h"

void	*ft_memcpy(void *dst, const void *src, size_t n)
{
	unsigned char	*d;
	unsigned char	*s;

	d = (unsigned char *)dst;
	s = (unsigned char *)src;
	if (!d && !s)
		return (NULL);
	while (n > 0)
	{
		*d++ = *s++;
		n--;
	}
	return (dst);
}

📖 참고 📖 restrict 키워드

  • 개념
    • C99 이후의 버전에서 사용 가능
    • restrict 키워드가 붙은 포인터가 가리키는 객체는 다른 포인터가 가리키지x
    • 프로그래머가 컴파일러에게 메모리 접근에 대한 최적화 요청하여 빠른 성능 보장 (동일한 메모리 접근이 없다는 것을 보장해야함)
    • 특정 메모리 영역에 접근 할 수 있는 포인터가 단 하나임을 보장하는 키워드
    • 다른 restrict 변수들과 같은 공간을 가리키지 않는다고 컴파일러에게 알려주는 것!

📕 10. ft_memmove

1) memmove 정의

  • header file
    • #include <string.h>
  • funtion prototype
    • void memmove(void dest, const void *src, size_t n);
  • description
    • 메모리 주소 src부터 n 바이트 만큼 dest에 중복되지 않게 복사 (memcpy와 차이)
    • src를 임시 장소에 복사를 하고 다시 이를 목적지에 복사함으로 overlap이 발생x
    • dest <= src
    • dest > src
  • return value
    • dest 포인터 반환
  • 참고 사이트

2) 구현

#include "libft.h"

void	*ft_memmove(void *dst, const void *src, size_t len)
{
	unsigned char	*temp;
	unsigned char	*value;

	temp = (unsigned char *)dst;
	value = (unsigned char *)src;
	if (!dst && !src)
		return (NULL);
	if (len < 0)
		len *= -1;
	if (temp < value)
		while (len-- > 0)
			*temp++ = *value++;
	else if (temp > value)
		while (len-- > 0)
			*(temp + len) = *(value + len);
	return (dst);
}

📕 11. ft_strlcpy

1) strlcpy 정의

  • header file
    • #include <string.h>
  • funtion prototype
    • size_t strlcpy(char dst, const char src, size_t dstsize);
  • description
    • 메모리 주소 src를 size - 1만큼 dst에 복사
    • null 종료 보장 (src가 null로 종료)
    • size는 dst 크기
  • return value
    • src 길이 반환

2) 구현

#include "libft.h"

size_t	ft_strlcpy(char	*dst, const char *src, size_t dstsize)
{
	size_t	len_s;

	len_s = ft_strlen(src);
	if (dstsize == 0)
		return (len_s);
	while (*src != '\0' && (dstsize - 1) > 0)
	{
		*dst++ = *src++;
		dstsize--;
	}
	*dst = '\0';
	return (len_s);
}

📕 12. ft_strlcat

1) strlcat 정의

  • header file
    • #include <string.h>
  • funtion prototype
    • size_t strlcat(char dst, const char src, size_t dstsize);
  • description
    • 메모리 주소 src을 size - 1만큼 dst 뒤에 연결 (dstsize - dst의 길이 - 1을 연결)
    • null 종료 보장 (src와 dst가 모두 null로 종료)
  • return value
    • size >= dst : dst 길이 + src 길이 반환
    • size < dst : size + src 길이 반환

2) 구현

#include "libft.h"

size_t	ft_strlcat(char *dst, const char *src, size_t dstsize)
{
	size_t	i;
	size_t	len_d;
	size_t	len_s;

	i = 0;
	len_d = ft_strlen(dst);
	len_s = ft_strlen(src);
	if (dstsize < len_d + 1)
		return (dstsize + len_s);
	if (dstsize >= len_d + 1)
	{
		while (*(src + i) != '\0' && len_d + i + 1 < dstsize)
		{
			*(dst + len_d + i) = *(src + i);
			i++;
		}
		*(dst + len_d + i) = '\0';
	}
	return (len_d + len_s);
}

📕 13. ft_strncmp

1) strncmp 정의

  • header file
    • #include <string.h>
  • funtion prototype
    • int strncmp(const char s1, const char s2, size_t n);
  • description
    • 문자열 s1과 s2를 비교하는 함수
    • null 만날 경우 종료
    • 값을 반환할 때, 128이상의 아스키코드 수를 계산할 경우를 위해 unsigned char형으로 변환
  • return value
    • 같을 경우 : 0 반환
    • 틀릴 경우 : s1 - s2 값의 차를 반환

2) 구현

#include "libft.h"

int	ft_strncmp(const char *s1, const char *s2, size_t n)
{
	unsigned char	*c1;
	unsigned char	*c2;

	c1 = (unsigned char *)s1;
	c2 = (unsigned char *)s2;
	while ((*c1 || *c2) && n > 0)
	{
		if (*c1 != *c2)
			return (*c1 - *c2);
		c1++;
		c2++;
		n--;
	}
	return (0);
}

📕 14. ft_toupper

1) toupper 정의

  • header file
    • #include <ctype.h>
  • funtion prototype
    • int toupper(int c);
  • description
    • 소문자를 대문자로 변환하는 함수
  • return value
    • lowercase일 경우 : uppercase 반환
    • uppercase일 경우 : 그대로 반환

2) 구현

int	ft_toupper(int c)
{
	if ('a' <= c && c <= 'z')
		return (c - 32);
	return (c);
}

📕 15. ft_tolower

1) tolower 정의

  • header file
    • #include <ctype.h>
  • funtion prototype
    • int tolower(int c);
  • description
    • 대문자를 소문자로 변환하는 함수
  • return value
    • uppercase일 경우 : lowercase 반환
    • lowercase일 경우 : 그대로 반환

2) 구현

int	ft_tolower(int c)
{
	if ('A' <= c && c <= 'Z')
		return (c + 32);
	return (c);
}          

📕 16. ft_strchr

1) strchr 정의

  • header file
    • #include <string.h>
  • funtion prototype
    • char strchr(const char s, int c);
  • description
    • 문자열 s에서 문자 c 검색 함수
    • null 문자도 비교 가능 (예외 처리)
    • 원본 s는 변경 불가능
  • return value
    • 찾을 경우 : 문자 c로 시작하는 문자열의 첫번째 주소 값 반환
    • 없을 경우 : null pointer 반환

2) 구현

  • s 널가드시 오류
char	*ft_strchr(const char *s, int c)
{
	while (*s)
	{
		if (*s == (char)c)
			return ((char *)s);
		s++;
	}
	if ((char)c == '\0')
		return ((char *)s);
	return (0);
}

📕 17. ft_strrchr

1) strrchr 정의

  • header file
    • #include <string.h>
  • funtion prototype
    • char strrchr(const char s, int c);
  • description
    • 문자열 s에서 마지막으로 나타난 문자 c 위치 검색 함수
    • null 문자도 비교 가능 (예외 처리)
  • return value
    • 찾을 경우 : 문자 c로 시작하는 문자열의 마지막 주소 값 반환
    • 없을 경우 : null pointer 반환

2) 구현

#include "libft.h"

char	*ft_strrchr(const char *s, int c)
{
	size_t	len;

	len = ft_strlen(s) + 1;
	while (len != 0)
	{
		if (s[len - 1] == (char)c)
			return ((char *)&s[len - 1]);
		len--;
	}
	return (0);
}

📕 18. ft_memchr

1) memchr 정의

  • header file
    • #include <string.h>
  • funtion prototype
    • void memchr(const void s, int c, size_t n);
  • description
    • 메모리 주소 s에서 문자 c 검색하는 함수
    • 문자를 바이트 단위로 찾는 함수
    • int로 받아와서 unsigned char로 변환해서 사용
  • return value
    • 찾을 경우 : 찾은 c 주소 반환
    • 없을 경우 : null 반환

2) 구현

unsigned char로 형변환된 c가 나타나는 곳을 위치시킴

#include "libft.h"

void	*ft_memchr(const void *s, int c, size_t n)
{
	unsigned char	*mem;
	unsigned char	check;

	mem = (unsigned char *)s;
	check = (unsigned char)c;
	while (n > 0)
	{
		if (*mem == check)
			return (mem);
		mem++;
		n--;
	}
	return (0);
}

📕 19. ft_memcmp

1) memcmp 정의

  • header file
    • #include <string.h>
  • funtion prototype
    • int memcmp(const void s1, const void s2, size_t n);
  • description
    • 문자열 s1과 s2를 n바이트 만큼 비교하는 함수
    • 문자열 비교시 unsigned char 자료형 사용
  • return value
    • 같을 경우 : 0을 반환
    • 다를 경우 : *s1 - *s2 값의 차이를 반환

2) 구현

#include "libft.h"

int	ft_memcmp(const void *s1, const void *s2, size_t n)
{
	unsigned char	*c1;
	unsigned char	*c2;

	c1 = (unsigned char *)s1;
	c2 = (unsigned char *)s2;
	while (n > 0)
	{
		if (*c1 != *c2)
			return (*c1 - *c2);
		c1++;
		c2++;
		n--;
	}
	return (0);
}

📕 20. ft_strnstr

1) strnstr 정의

  • header file
    • #include <string.h>
  • funtion prototype
    • char strnstr(const char s1, const char *s2, size_t n);
  • description
    • 문자열 s1 내에서 부분 문자열 s2를 찾는 함수 (문자열 시작부터 n까지)
  • return value
    • 찾을 경우 : s2의 시작 주소 반환
    • s2가 비었을 경우 : s1의 시작 주소 반환
    • 찾지 못할 경우 : null 반환

2) 구현

#include "libft.h"

char	*ft_strnstr(const char *haystack, const char *needle, size_t len)
{
	size_t	len2;

	if (!*needle)
		return ((char *)haystack);
	len2 = ft_strlen(needle);
	while (*haystack != 0 && len >= len2)
	{
		if (ft_strncmp(haystack, needle, len2) == 0)
			return ((char *)haystack);
		haystack++;
		len--;
	}
	return (0);
}

// Main Example
int main()
{
	char	*p_src_str = "abcdefg";
    char	*p_find_str = "cde";
    char	*p_pos;
    int		n = 2;
    
    p_pos = strnstr(p_src_str, p_find_str, n);
    
    if (!p_pos)
    	return (0);
    printf("기준 문자열 : %s\n", p_src_str);
    printf("찾을 문자열 : %s\n", p_find_str);
    printf("찾은 위치 : %s\n", p_pos);
}c

📕 21. ft_atoi

1) atoi 정의

  • header file : <stdlib.h>
  • funtion prototype
    • int atoi(const char *nptr);
  • description
    • string을 integer로 변환하는 함수
    • +/-가 2개 이상 나오면 0 반환
  • return value
    • integer 반환

2) 구현

#include "libft.h"

static int	is_space(char c)
{
	if (c == ' ' || c == '\r' || c == '\f'
		|| c == '\t' || c == '\v' || c == '\n')
		return (1);
	return (0);
}

int	ft_atoi(const char *str)
{
	size_t	value;
	size_t	sign;

	value = 0;
	sign = 1;
	while (is_space(*str))
		str++;
	if (*str == '-' || *str == '+')
	{
		if (*str == '-')
			sign *= -1;
		str++;
	}
	while (*str >= '0' && *str <= '9')
	{
		value = (value * 10) + (*str - '0');
		str++;
	}
	return ((int)(value * sign));
}

📕 22. ft_calloc

1) calloc 정의

  • header file : <stdlib.h>
  • funtion prototype
    • void *calloc(size_t n, size_t size);
  • description
    • size만큼의 크기를 가지는 자료형을 n개 만큼 가지게 동적할당 하는 함수
    • 값을 모두 0으로 초기화
      = malloc + bzero
  • return value
    • calloc한 배열 반환

2) 구현

  • 허용 함수 : malloc
#include "libft.h"

void	*ft_calloc(size_t count, size_t size)
{
	void	*p;

	p = (void *)malloc(count * size);
	if (!p)
		return (NULL);
	ft_bzero(p, (count * size));
	return (p);
}

📕 23. ft_strdup

1) strdup 정의

  • header file : <string.h>
  • funtion prototype
    • char strdup(const char s);
  • description
    • strcpy와 유사하지만 malloc 이용하여 동적할당 받은 후 복사 (깊은 복사)
    • = malloc + strcpy
  • return value
    • 동적 할당 후 복사된 string 반환

2) 구현

  • 허용 함수 : malloc
#include "libft.h"

char	*ft_strdup(const char *s)
{
	char	*p;
	size_t	i;
	size_t	len;

	i = 0;
	len = ft_strlen(s);
	p = (char *)malloc(sizeof(char) * (len + 1));
	if (!p)
		return (NULL);
	while (*(s + i) != '\0')
	{
		*(p + i) = *(s + i);
		i++;
	}
	*(p + i) = '\0';
	return (p);
}

📒 Additional functions

📕 1. ft_substr

1) substr 정의

  • header file : <string.h>
  • funtion prototype
    • char ft_substr(char const s, unsigned int start, size_t len);
  • description
    • 문자열 s의 start부터 len까지 자른 문자열 반환
    • len > s일 경우 s의 문자열을 끝까지만 자르도록 처리
  • return value
    • len <= len(s) - start : s가 끝나면 substr도 끝나고 문자열 반환
    • start >= len(s) 경우 : 빈 문자열 반환
    • 할당 실패할 경우 : null 반환
    • 빈 문자열 -> 빈 문자열 반환 / null -> null 반환

2) 구현

  • 허용 함수 : malloc
#include "libft.h"

char	*ft_substr(char const *s, unsigned int start, size_t len)
{
	char		*sub;
	size_t		i;
	size_t		slen;

	if (!s)
		return (NULL);
	i = 0;
	slen = ft_strlen(s);
	if (start > slen || len == 0)
		return (ft_strdup(""));
	if (len > slen - start)
		len = slen - start;
	sub = (char *)malloc(sizeof(char) * (len + 1));
	if (!sub)
		return (NULL);
	while (*(s + start + i) != '\0' && len > i)
	{
		*(sub + i) = *(s + start + i);
		i++;
	}
	*(sub + i) = '\0';
	return (sub);
}

// Main Example
#include <stdio.h>

int	main(void)
{
	char *str = "01234";
    size_t size = 10;
    char *ret = ft_substr(str, 10, size);
	printf("%s\n", ret);
	return (0);
}

📕 2. ft_strjoin

1) strjoin 정의

  • header file : <string.h>
  • funtion prototype
    • char ft_strjoin(char const s1, char const *s2);
  • description
    • strcat와 유사하지만 malloc 이용하여 동적할당 받은 후 연결
  • return value
    • s1 + s2 연결한 길이만큼 동적할당 후 연결된 string 반환
    • 둘다 null인 경우, null을 반환하고 그렇지 않을 경우 값이 있는 경우만 처리
    • 할당 실패할 경우 : null 반환

2) 구현

  • 허용 함수 : malloc
#include "libft.h"

char	*ft_strjoin(char const *s1, char const *s2)
{
	char	*p;
	size_t	len1;
	size_t	len2;

	if (!s1 && !s2)
		return (NULL);
	else if (!s1)
		return (ft_strdup(s2));
	else if (!s2)
		return (ft_strdup(s1));
	len1 = ft_strlen(s1);
	len2 = ft_strlen(s2);
	p = (char *)malloc(sizeof(char) * (len1 + len2 + 1));
	if (!p)
		return (NULL);
	ft_strlcpy(p, s1, len1 + 1);
	ft_strlcat(p + len1, s2, len2 + 1);
	return (p);
}

📕 3. ft_strtrim

1) 정의

  • header file : <string.h>
  • funtion prototype
    • char ft_strtrim(char const s, char const *set);
  • description
    • 문자열 s의 앞/뒤에 존재하는 sep 구분문자 제거
    • 처음과 끝 인덱스 구한 후 동적할당 후 strlcpy 이용
  • return value
    • sep 구분문자들을 제거한 문자열 반환
    • 빈 문자열 -> 빈 문자열 반환

2) 구현

  • 허용 함수 : malloc
#include "libft.h"

char	*ft_strtrim(char const *s, char const *set)
{
	size_t		i;
	size_t		len;
	char		*trim;

	if (!s || !set)
		return (NULL);
	i = 0;
	len = ft_strlen(s);
	while (s[i] != '\0' && ft_strchr(set, s[i]))
		i++;
	while (s[len - 1] != '\0' && len > 0 && ft_strchr(set, s[len - 1]))
		len--;
	if (i > len)
		return (ft_strdup(""));
	trim = (char *)malloc(sizeof(char) * (len - i + 1));
	if (!trim)
		return (NULL);
	ft_strlcpy(trim, &s[i], len - i + 1);
	return (trim);
}

// Main Example
int main()
{
	printf("%s\n", ft_strtrim("abqbc", "abc"));
	printf("%s\n", ft_strtrim("xavocadoyz", "xyz"));
	return 0;
}

📕 4. ft_split

1) 정의

  • header file : <string.h>
  • funtion prototype
    • char **ft_split(char const *s, char c);
  • description
    • 구분문자 c 기준으로 문자열 s를 자르는 함수
    • 2차원 배열로 동적 할당한 배열에 인덱싱을 해서 다시 동적할당
  • return value
    • 할당 성공할 경우 : split된 string을 모아둔 char 배열을 반환
    • 할당 실패할 경우 : null 반환

2) 구현

  • 허용 함수 : malloc, free
#include "libft.h"

static char	*ft_sub_split(const char *s, char c)
{
	size_t	i;
	size_t	len;
	char	*sub;

	i = 0;
	len = 0;
	if (!s)
		return (NULL);
	while (*(s + len) != c && *(s + len))
		len++;
	sub = (char *)malloc(sizeof(char) * (len + 1));
	if (!sub)
		return (NULL);
	while (len > i)
	{
		*(sub + i) = *(s + i);
		i++;
	}
	*(sub + i) = '\0';
	return (sub);
}

static char	**ft_real_split(char const *s, char c, char **split, size_t count)
{
	size_t	i;

	i = 0;
	while (count > i)
	{
		while (*s == c && *s)
			s++;
		*(split + i) = ft_sub_split(s, c);
		if (!*(split + i))
		{
			while (i--)
				free(*(split + i));
			free(split);
			return (NULL);
		}
		i++;
		while (*s != c && *s)
			s++;
	}
	*(split + count) = NULL;
	return (split);
}

char	**ft_split(char const *s, char c)
{
	size_t	i;
	size_t	count;
	char	**split;

	i = 0;
	count = 0;
	if (!s)
		return (NULL);
	while (*(s + i))
	{
		if (*(s + i) == c)
			i++;
		else
		{
			count++;
			while (*(s + i) != c && *(s + i))
				i++;
		}
	}
	split = (char **)malloc(sizeof(char *) * (count + 1));
	if (!split)
		return (NULL);
	split = ft_real_split(s, c, split, count);
	return (split);
}

#include <stdio.h>

int	main(void)
{
	char *s;
	char c;
	char **words;

	s = "asdf2439#85723RETV#WYWER5w%^YW#$%6";
	c = '';
	words = ft_split(s1, s2);
	if (!*words) printf("(blank)\n");
	while (*words)
		printf("#1 - %s\n", *(words++));
	printf("\n");
}

📕 5. ft_itoa

1) 정의

  • header file : <string.h>
  • funtion prototype
    • char *ft_itoa(int n);
  • description
    • integer를 str 배열로 바꾸는 함수
    • 정수의 자리수를 구한 후 일의 자리부터 값 채우기
  • return value
    • 할당 성공할 경우 : integer를 변환 한 string 반환
    • 할당 실패할 경우 : null 반환

2) 구현

  • 허용 함수 : malloc
#include "libft.h"

static size_t	ft_size(int n)
{
	size_t	size;

	size = 0;
	if (n < 0)
		size++;
	else if (n == 0)
		size++;
	while (n != 0)
	{
		n = n / 10;
		size++;
	}
	return (size);
}

char	*ft_itoa(int n)
{
	size_t		size;
	char		*str;
	long long	ln;

	size = ft_size(n);
	str = (char *)malloc(sizeof(char) * (size + 1));
	if (!str)
		return (NULL);
	ln = (long long)n;
	if (ln < 0)
	{
		str[0] = '-';
		ln *= -1;
	}
	if (ln == 0)
		str[0] = '0';
	str[size--] = '\0';
	while (ln != 0)
	{
		str[size--] = ln % 10 + '0';
		ln /= 10;
	}
	return (str);
}

//Main Example
int main()
{
	printf("%s\n", ft_itoa(0));
	printf("%s\n", ft_itoa(987654321));
	printf("%s\n", ft_itoa(-123456789));
}

📕 6. ft_strmapi

1) 정의

  • header file : <string.h>
  • funtion prototype
    • char ft_strmapi(char const s, char (*f)(unsigned int, char));
  • description
    • 함수 포인터를 이용하여 s 문자열에 함수를 적용시키는 함수
    • 함수 f를 적용할 때 문자의 index와 문자의 매개변수를 인자로 받음
    • unsigend int는 현재 char의 index값 (해당 문자의 인덱스를 함수 'f'의 첫 번째 인자로 사용)
  • return value
    • 할당 성공할 경우 : 함수 f를 적용시킨 새로운 문자열을 반환
    • 할당 실패할 경우 : null 반환

2) 구현

  • 허용 함수 : malloc
#include "libft.h"

char	*ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
	size_t	i;
	size_t	len;
	char	*str;

	if (!s)
		return (NULL);
	i = 0;
	len = ft_strlen(s);
	str = (char *)malloc(sizeof(char) * (len + 1));
	if (!str)
		return (NULL);
	while (len > i)
	{
		if (f != NULL)
			str[i] = f(i, s[i]);
		i++;
	}
	str[i] = '\0';
	return (str);
}

// Main Example
#include <stdio.h>

char f(unsigned int i, char c)
{
	char str;
	str = c + 1;
	return (str);
}

int main()
{
	char str1[] = "abc";
	char* str2;
	str2 = ft_strmapi(str1, *f);
	printf("%s\n", str2);
}

📖 참고 📖 함수 포인터

  • 개념
    • 함수의 주소를 저장하는 변수
    • 상수 함수 포인터 : (*const 함수 포인터 이름)
    • 할당 : int (*fp)() = 함수 이름;
    • 호출 : (*fp)();
  • 참고 사이트

📕 7. ft_striteri

1) 정의

  • header file : <string.h>
  • funtion prototype
    • void ft_striteri(char s, void (f)(unsigned int, char*));
  • description
    • 문자열 s를 순회하며 함수 f를 적용시키는 함수
    • 함수 f를 적용할 때 문자의 index와 문자의 주소값(포인터)를 인자로 받음
  • return value
    • 없음

2) 구현

#include "libft.h"

void	ft_striteri(char *s, void (*f)(unsigned int, char *))
{
	size_t	i;
	size_t	len;

	if (!s)
		return ;
	i = 0;
	len = ft_strlen(s);
	while (len > i)
	{
		if (f != NULL)
			f(i, &s[i]);
		i++;
	}
}

📕 8. ft_putchar_fd

1) 정의

  • header file : <string.h>
  • funtion prototype
    • void ft_putchar_fd(char c, int fd);
  • description
    • fd(file descriptor)에 문자 c 출력
  • return value
    • 없음

2) 구현

  • 허용 함수 : write
#include "libft.h"

void	ft_putchar_fd(char c, int fd)
{
	write(fd, &c, 1);
}

📖 참고 📖 File Descriptor

  • 개념
    • 유닉스 시스템에서 프로세스 파일을 다루는 도구
    • File Descriptor는 0이 아닌 양의 정수값(Non-negative Integer)을 가짐
    • 프로세스가 실행 중에 파일을 open하면 사용하지 않은 숫자 중 가장 작은 값 할당
    • 프로세스가 열려있는 파일에 시스템 콜을 이용하여 접근할 때, File Descriptor 이용해서 파일을 지칭 가능
  • 기본적으로 할당되는 파일 디스크립터
    • 0 : Standard Input
    • 1 : Standart Output
    • 2 : Standard Error
  • 참고 사이트

📕 9. ft_putstr_fd

1) 정의

  • header file : <string.h>
  • funtion prototype
    • void ft_putstr_fd(char *s, int fd);
  • description
    • fd(file descriptor)에 문자열 s 출력
  • return value
    • 없음

2) 구현

  • 허용 함수 : write
#include "libft.h"

void	ft_putstr_fd(char *s, int fd)
{
	if (s != NULL)
	{
		while (*s != '\0')
		{
			write(fd, s, 1);
			s++;
		}
	}
}

📕 10. ft_putendl_fd

1) 정의

  • header file : <string.h>
  • funtion prototype
    • void ft_putendl_fd(char *s, int fd);
  • description
    • fd(file descriptor)에 문자열 s 출력 + 개행(줄바꿈) 출력
  • return value
    • 없음

2) 구현

  • 허용 함수 : write
#include "libft.h"

void	ft_putendl_fd(char *s, int fd)
{
	if (s != NULL)
	{
		while (*s)
		{
			write(fd, s, 1);
			s++;
		}
		write(fd, "\n", 1);
	}
}

📕 11. ft_putnbr_fd

1) 정의

  • header file : <string.h>
  • funtion prototype
    • void ft_putnber_fd(int n, int fd);
  • description
    • fd(file descriptor)에 정수 n 출력
  • return value
    • 없음

2) 구현

  • 허용 함수 : write
#include "libft.h"

void	ft_putnbr_fd(int n, int fd)
{
	long long	nbr;
	char		c;

	nbr = (long long)n;
	if (nbr < 0)
	{
		write(fd, "-", 1);
		nbr *= -1;
	}
	if (nbr >= 10)
		ft_putnbr_fd(nbr / 10, fd);
	c = nbr % 10 + '0';
	write(fd, &c, 1);
}

Makefile

NAME = libft.a

SRCS = ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c \
	   ft_strlen.c \
	   ft_memset.c ft_bzero.c ft_memcpy.c ft_memmove.c \
	   ft_strlcpy.c ft_strlcat.c \
	   ft_toupper.c ft_tolower.c \
	   ft_strchr.c ft_strrchr.c ft_strncmp.c \
	   ft_memchr.c ft_memcmp.c \
	   ft_strnstr.c \
	   ft_atoi.c ft_calloc.c \
	   ft_strdup.c ft_substr.c ft_strjoin.c ft_strtrim.c ft_split.c ft_itoa.c \
	   ft_strmapi.c ft_striteri.c \
	   ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c

OBJS = $(SRCS:.c=.o)

%.o : %.c libft.h
	cc -Wall -Wextra -Werror -c $< -o $@

$(NAME) : $(OBJS)
	ar rc $@ $(OBJS)

all : $(NAME)

clean :
	rm -rf $(OBJS)

fclean : clean
	rm -rf $(NAME)

re : fclean all

.PHONY : all clean fclean re

libft.h

#ifndef LIBFT_H
# define LIBFT_H

# include <stdlib.h>
# include <unistd.h>

int			ft_isalpha(int c);
int			ft_isdigit(int c);
int			ft_isalnum(int c);
int			ft_isascii(int c);
int			ft_isprint(int c);
void		*ft_memset(void *b, int c, size_t n);
void		ft_bzero(void *s, size_t n);
void		*ft_memcpy(void *dst, const void *src, size_t n);
void		*ft_memmove(void *dst, const void *src, size_t n);
size_t		ft_strlen(const char *s);
size_t		ft_strlcpy(char	*dst, const char *src, size_t dstsize);
size_t		ft_strlcat(char *dst, const char *src, size_t dstsize);
int			ft_toupper(int c);
int			ft_tolower(int c);
char		*ft_strchr(const char *s, int c);
char		*ft_strrchr(const char *s, int c);
int			ft_strncmp(const char *s1, const char *s2, size_t n);
void		*ft_memchr(const void *s, int c, size_t n);
int			ft_memcmp(const void *s1, const void *s2, size_t n);
char		*ft_strnstr(const char *haystack, const char *needle, size_t len);
int			ft_atoi(const char *str);
void		*ft_calloc(size_t n, size_t size);
char		*ft_strdup(const char *s);
char		*ft_substr(const char *s, unsigned int start, size_t len);
char		*ft_strjoin(const char *s1, const char *s2);
char		*ft_strtrim(const char *s, const char *set);
char		**ft_split(const char *s, char c);
char		*ft_itoa(int n);
char		*ft_strmapi(const char *s, char (*f)(unsigned int, char));
void		ft_striteri(char *s, void (*f)(unsigned int, char*));
void		ft_putchar_fd(char c, int fd);
void		ft_putstr_fd(char *s, int fd);
void		ft_putendl_fd(char *s, int fd);
void		ft_putnbr_fd(int n, int fd);

#endif

📒 Bonus Part

  • libft.h 파일에 구조체 추가

📖 참고 📖 연결리스트

  • 개념
    • 배열과 달리 크기를 자유롭게 변경할 수 있는 자료구조
    • 노드(리스트 내 각 요소)를 연결해서 만드는 리스트
    • head : 리스트의 첫 번째 노드
    • tail : 리스트의 마지막 노드
  • 특징
    • 장점 : 새로운 노드의 추가/삽입/삭제가 쉽고 빠름
    • 단점 : 특정 위치에 있는 노드를 검색하는데 비용이 크고, 속도가 느림
  • 참고 사이트

📕 1. ft_lstnew

1) 정의

  • header file : <string.h>
  • function prototype
    • t_list *ft_lstnew(void *content);
  • description
    • 새로운 노드를 생성하는 함수
    • node의 content에는 content로 초기화
    • node의 next(다음 노드의 포인터)에는 null로 초기화
  • return value
    • 동적할당한 새로운 node

📖 참고 📖 malloc으로 메모리를 할당 이유

  • malloc없이 새로운 노드를 만들게 되면, 해당 함수가 종료되면서 반환되는 new 노드는 stack에서 사라짐
  • malloc을 하면 힙영역에 할당되고, 메모리 상에 남아 t_list *new 가 할당 받은 메모리를 가리킬 수 있음
  • 메모리 구조

2) 구현

  • 허용 함수 : malloc
#include "libft.h"

t_list	*ft_lstnew(void *content)
{
	t_list	*new;

	new = (t_list *)malloc(sizeof(t_list));
	if (!new)
		return (NULL);
	new->content = content;
	new->next = NULL;
	return (new);
}

#include <stdio.h>

int	main(void)
{
	t_list	*head;
    void	*content;
    
    head = NULL;
    content = "abc";
    head = ft_lstnew(content);
}

📕 2. ft_lstadd_front

1) 정의

  • header file : <string.h>
  • function prototype
    • void ft_lstadd_front(t_list *lst, t_list new);
  • description
    • 리스트 맨 앞에 new node를 추가하는 함수
    • **lst : t_list 포인터(lst)의 주소를 가리키는 포인터
    • 새 노드의 다음 주소를 head로 설정
  • return value
    • 없음

📖 참고 📖 연결 리스트 구현시 이중 포인터를 사용하는 이유

  • 단일 연결리스트에서 삽입과 삭제를 통해 head 포인터의 값을 변화 가능
  • 호출 함수의 포인터변수가 참조하는 객체를 피호출 함수에서 바꾸고자 할 경우 이중 포인터를 사용
  • t_list **lst 변수가 담고있는 값은 t_list *의 주소 (= *lst는 head의 주소)

2) 구현

#include "libft.h"

void	ft_lstadd_front(t_list **lst, t_list *new)
{
	t_list	*new_last;

	if (lst != NULL && new != NULL)
	{
		new_last = ft_lstlast(new);
		new_last->next = *lst;
		*lst = new;
	}
}

#include <stdio.h>

int main(void)
{
	t_list *head;
    t_list *front;
    
    head = (t_list *)malloc(sizeof(t_list));
    head->content = "a";
    head->next = NULL;
}

📕 3. ft_lstsize

1) 정의

  • header file : <string.h>
  • function prototype
    • int ft_lstsize(t_list *lst);
  • description
    • 리스트에 포함되어 있는 node의 개수를 세는 함수
  • return value
    • 연결리스트에 있는 node의 개수 반환

2) 구현

#include "libft.h"

int	ft_lstsize(t_list *lst)
{
	size_t	size;

	size = 0;
	while (lst != NULL)
	{
		lst = lst->next;
		size++;
	}
	return (size);
}

📕 4. ft_lstlast

1) 정의

  • header file : <string.h>
  • function prototype
    • t_list ft_lstlast(t_list lst);
  • description
    • 연결리스트의 마지막 노드로 이동하는 함수
  • return value
    • 연결리스트의 마지막에 위치한 node 반환

2) 구현

#include "libft.h"

t_list	*ft_lstlast(t_list *lst)
{
	if (lst == NULL)
		return (NULL);
	while (lst->next != NULL)
		lst = lst->next;
	return (lst);
}

📕 5. ft_lstadd_back

1) 정의

  • header file : <string.h>
  • function prototype
    • void ft_lstadd_back(t_list **lst, t_list *new);
  • description
    • 리스트의 마지막에 new node를 삽입하는 함수
    • new의 다음 주소 = 원래 last의 다음주소 (=NULL)로 설정
    • last의 다음 주소가 new를 가리키도록 변경
  • return value
    • 없음

📖 참고 📖 *lst == NULL 과 lst == NULL 의 차이

  • *lst == NULL : lst의 첫번째 주소 (헤드의 주소를 의미) 헤드가 비었다는 건, *lst는 빈 리스트 라는 의미
  • lst == NULL : 리스트 자체가 존재하지 않는다는 의미

2) 구현

#include "libft.h"

void	ft_lstadd_back(t_list **lst, t_list *new)
{
	t_list	*last;

	if (lst != NULL && new != NULL)
	{
		if (*lst != NULL)
		{
			last = ft_lstlast(*lst);
			last->next = new;
		}
		else
			*lst = new;
	}
}

📕 6. ft_lstdelone

1) 정의

  • header file : <string.h>
  • function prototype
    • void ft_lstdelone(t_list *lst, void (*del)(void *));
  • description
    • 연결 리스트 노드 데이터를 삭제하는 함수
    • lst의 content를 del 함수 포인터를 이용해 해제하고, lst의 메모리 해제
    • next 포인터는 해제X
    • del 함수로 content 변수 free
    • free 이용해 lst 요소 free
  • return value
    • 없음

📖 참고 📖 free(lst)만 하면 안되는 이유

  • content 변수는 주소만 담고 있음
  • 주소가 가리키는 값까지 삭제를 해줘야 하는데, free(lst)를 한 후에는 lst->content 로 접근이 불가능
  • content를 먼저 free해주고 그 다음에 lst를 free 필요함

2) 구현

  • 허용 함수 : free
#include "libft.h"

void	ft_lstdelone(t_list *lst, void (*del)(void *))
{
	if (lst != NULL)
	{
		if (del != NULL)
			del(lst->content);
		free(lst);
	}
}

📕 7. ft_lstclear

1) 정의

  • header file : <string.h>
  • function prototype
    • void ft_lstclear(t_list *lst, void (del)(void
      *));
  • description
    • 연결 리스트 전체 노드 데이터를 삭제하는 함수
    • lst의 따라오는 모든 요소들을 del과 free이용하여 삭제
    • 리스트의 포인터는 마지막에 NULL로 설정
  • return value
    • 없음

2) 구현

  • 허용 함수 : free
#include "libft.h"

void	ft_lstclear(t_list **lst, void (*del)(void *))
{
	t_list	*clear;
	t_list	*next;

	clear = *lst;
	while (clear != NULL)
	{
		next = clear->next;
		if (del != NULL)
			del(clear->content);
		free(clear);
		clear = next;
	}
	*lst = NULL;
}

📕 8. ft_lstiter

1) 정의

  • header file : <string.h>
  • function prototype
    • void ft_lstiter(t_list lst, void (f)(void *));
  • description
    • 리스트를 반복하면서 특정 함수 적용시키는 함수
    • 리스트의 모든 node->content에 함수 f를 적용시키는 함수
    • striteri와 유사
  • return value
    • 없음

2) 구현

#include "libft.h"

void	ft_lstiter(t_list *lst, void (*f)(void *))
{
	if (lst != NULL)
	{
		while (lst != NULL)
		{
			if (f != NULL)
				f(lst->content);
			lst = lst->next;
		}
	}
}

📕 9. ft_lstmap

1) 정의

  • header file : <string.h>

  • function prototype

    • t_list ft_lstmap(t_list lst, void (f)(void ),
      void (
      del)(void *));
  • description

    • 리스트의 모든 node->content에 함수 f를 적용 시킨 후 새로운 리스트 생성
    • del은 각 node의 content 삭제시 사용
  • return value

    • 함수 f를 적용한 list 반환

2) 구현

  • 허용 함수 : malloc, free
#include "libft.h"

t_list	*ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
	t_list	*map;
	t_list	*tmp;
	void	*d;

	if (!lst || !f)
		return (NULL);
	map = NULL;
	while (lst != NULL)
	{
		d = f(lst->content);
		tmp = ft_lstnew(d);
		if (!tmp)
		{
			if (del != NULL)
				del(d);
			ft_lstclear(&map, del);
			return (NULL);
		}
		ft_lstadd_back(&map, tmp);
		lst = lst->next;
	}
	return (map);
}

Makefile (bonus)

NAME = libft.a

SRCS = ft_isalpha.c \
	   ft_isdigit.c \
	   ft_isalnum.c \
	   ft_isascii.c \
	   ft_isprint.c \
	   ft_strlen.c \
	   ft_memset.c \
	   ft_memcpy.c \
	   ft_memmove.c \
	   ft_strlcpy.c \
	   ft_strlcat.c \
	   ft_toupper.c \
	   ft_tolower.c \
	   ft_strchr.c \
	   ft_strrchr.c \
	   ft_strncmp.c \
	   ft_memchr.c \
	   ft_memcmp.c \
	   ft_strnstr.c \
	   ft_atoi.c \
	   ft_calloc.c \
	   ft_strdup.c \
	   ft_substr.c \
	   ft_strjoin.c \
	   ft_strtrim.c \
	   ft_split.c \
	   ft_itoa.c \
	   ft_strmapi.c \
	   ft_striteri.c \
	   ft_putchar_fd.c \
	   ft_putstr_fd.c \
	   ft_putendl_fd.c \
	   ft_putnbr_fd.c \
	   ft_bzero.c

SRCS_BN = ft_lstadd_front.c \
		  ft_lstsize.c \
		  ft_lstdelone.c \
		  ft_lstclear.c \
		  ft_lstiter.c \
		  ft_lstmap.c \
		  ft_lstnew.c \
		  ft_lstlast.c \
		  ft_lstadd_back.c

OBJS = $(SRCS:.c=.o)

OBJS_BONUS = $(SRCS_BN:.c=.o)

all : $(NAME)

$(NAME) : $(OBJS)

%.o : %.c libft.h
	cc -Wall -Wextra -Werror -c $< -o $@
	ar rc $(NAME) $@

clean :
	rm -rf $(OBJS) $(OBJS_BONUS)
	rm -rf bonus

fclean : clean
	rm -rf $(NAME)

re : fclean all

bonus : $(OBJS) $(OBJS_BONUS)

.PHONY : all clean fclean re bonus

libft.h (bonus)

#ifndef LIBFT_H
# define LIBFT_H

# include <stdlib.h>
# include <unistd.h>

typedef struct s_list
{
	void			*content;
	struct s_list	*next;
}t_list;

int			ft_isalpha(int c);
int			ft_isdigit(int c);
int			ft_isalnum(int c);
int			ft_isascii(int c);
int			ft_isprint(int c);
void		*ft_memset(void *b, int c, size_t len);
void		ft_bzero(void *s, size_t n);
void		*ft_memcpy(void *dst, const void *src, size_t n);
void		*ft_memmove(void *dst, const void *src, size_t len);
size_t		ft_strlen(const char *s);
size_t		ft_strlcpy(char	*dst, const char *src, size_t dstsize);
size_t		ft_strlcat(char *dst, const char *src, size_t dstsize);
int			ft_toupper(int c);
int			ft_tolower(int c);
char		*ft_strchr(const char *s, int c);
char		*ft_strrchr(const char *s, int c);
int			ft_strncmp(const char *s1, const char *s2, size_t n);
void		*ft_memchr(const void *s, int c, size_t n);
int			ft_memcmp(const void *s1, const void *s2, size_t n);
char		*ft_strnstr(const char *haystack, const char *needle, size_t len);
int			ft_atoi(const char *str);
void		*ft_calloc(size_t count, size_t size);
char		*ft_strdup(const char *s);
char		*ft_substr(char const *s, unsigned int start, size_t len);
char		*ft_strjoin(char const *s1, char const *s2);
char		*ft_strtrim(char const *s, char const *set);
char		**ft_split(char const *s, char c);
char		*ft_itoa(int n);
char		*ft_strmapi(char const *s, char (*f)(unsigned int, char));
void		ft_striteri(char *s, void (*f)(unsigned int, char*));
void		ft_putchar_fd(char c, int fd);
void		ft_putstr_fd(char *s, int fd);
void		ft_putendl_fd(char *s, int fd);
void		ft_putnbr_fd(int n, int fd);
t_list		*ft_lstnew(void *content);
void		ft_lstadd_front(t_list **lst, t_list *new);
int			ft_lstsize(t_list *lst);
t_list		*ft_lstlast(t_list *lst);
void		ft_lstadd_back(t_list **lst, t_list *new);
void		ft_lstdelone(t_list *lst, void (*del)(void *));
void		ft_lstclear(t_list **lst, void (*del)(void *));
void		ft_lstiter(t_list *lst, void (*f)(void *));
t_list		*ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void*));

#endif

📒 결과

profile
Notion으로 이동 (https://24tngus.notion.site/3a6883f0f47041fe8045ef330a147da3?v=973a0b5ec78a4462bac8010e3b4cd5c0&pvs=4)

0개의 댓글