├── ft_isprint.c ├── ft_isascii.c ├── ft_isdigit.c ├── ft_putchar_fd.c ├── ft_tolower.c ├── ft_toupper.c ├── ft_bzero.c ├── ft_putendl_fd.c ├── ft_isalnum.c ├── ft_putstr_fd.c ├── ft_strlen.c ├── ft_lstadd_front.c ├── ft_lstiter.c ├── ft_lstlast.c ├── ft_memset.c ├── ft_lstdelone.c ├── ft_lstsize.c ├── ft_calloc.c ├── ft_memchr.c ├── ft_lstclear.c ├── ft_striteri.c ├── ft_lstnew.c ├── ft_strchr.c ├── ft_strrchr.c ├── ft_memcpy.c ├── ft_lstadd_back.c ├── ft_strncmp.c ├── ft_memmove.c ├── ft_putnbr_fd.c ├── ft_isalpha.c ├── ft_strdup.c ├── ft_strlcpy.c ├── ft_memcmp.c ├── ft_strmapi.c ├── ft_lstmap.c ├── ft_strnstr.c ├── ft_strjoin.c ├── ft_atoi.c ├── ft_substr.c ├── ft_strlcat.c ├── ft_strtrim.c ├── ft_itoa.c ├── Makefile ├── ft_split.c ├── libft.h └── README.md /ft_isprint.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isprint.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/02 08:26:08 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/05 09:03:37 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isprint(int c) 14 | { 15 | return (c >= 32 && c <= 126); 16 | } 17 | -------------------------------------------------------------------------------- /ft_isascii.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isascii.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/02 08:24:06 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/04 11:57:55 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isascii(int c) 14 | { 15 | if (c >= 0 && c <= 127) 16 | return (1); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /ft_isdigit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* is_digit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/01 17:10:22 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/05 08:03:53 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isdigit(int c) 14 | { 15 | if (c >= '0' && c <= '9') 16 | return (1); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /ft_putchar_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/04 13:41:29 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/05 08:10:38 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putchar_fd(char c, int fd) 16 | { 17 | write(fd, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /ft_tolower.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_tolower.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/02 08:29:58 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/05 08:18:07 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_tolower(int c) 14 | { 15 | if (c >= 65 && c <= 90) 16 | return (c + 32); 17 | return (c); 18 | } 19 | -------------------------------------------------------------------------------- /ft_toupper.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_toupper.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/02 08:27:37 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/04 12:07:08 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_toupper(int c) 14 | { 15 | if (c >= 97 && c <= 122) 16 | return (c - 32); 17 | return (c); 18 | } 19 | -------------------------------------------------------------------------------- /ft_bzero.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_bzero.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/06 10:25:44 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/07 09:59:29 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_bzero(void *s, size_t n) 16 | { 17 | while (n--) 18 | *((unsigned char *)(s + n)) = 0; 19 | } 20 | -------------------------------------------------------------------------------- /ft_putendl_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putendl_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/04 13:49:01 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/05 08:10:53 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putendl_fd(char *s, int fd) 16 | { 17 | ft_putstr_fd(s, fd); 18 | ft_putchar_fd('\n', fd); 19 | } 20 | -------------------------------------------------------------------------------- /ft_isalnum.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalnum.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/01 17:19:01 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/04 12:00:51 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isalnum(int c) 16 | { 17 | if (ft_isdigit(c) || ft_isalpha(c)) 18 | return (1); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /ft_putstr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/04 13:42:21 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/05 17:34:50 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putstr_fd(char *s, int fd) 16 | { 17 | if (!s) 18 | return ; 19 | while (*s) 20 | ft_putchar_fd(*(s++), fd); 21 | } 22 | -------------------------------------------------------------------------------- /ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/01 16:28:29 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/04 12:19:02 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlen(const char *s) 16 | { 17 | size_t l; 18 | 19 | l = 0; 20 | while (s[l]) 21 | l++; 22 | return (l); 23 | } 24 | -------------------------------------------------------------------------------- /ft_lstadd_front.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_front.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/06 11:49:35 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/08 15:19:19 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_front(t_list **lst, t_list *new) 16 | { 17 | if (lst && new) 18 | new->next = *lst; 19 | if (new) 20 | *lst = new; 21 | } 22 | -------------------------------------------------------------------------------- /ft_lstiter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstiter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/07 06:45:01 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/07 07:53:05 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstiter(t_list *lst, void (*f)(void *)) 16 | { 17 | while (lst && f) 18 | { 19 | f(lst->content); 20 | lst = lst->next; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ft_lstlast.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstlast.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/06 18:30:39 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/06 18:34:09 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstlast(t_list *lst) 16 | { 17 | if (!lst) 18 | return (NULL); 19 | while (lst->next) 20 | lst = lst->next; 21 | return (lst); 22 | } 23 | -------------------------------------------------------------------------------- /ft_memset.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memset.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/06 09:34:32 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/06 09:41:37 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memset(void *b, int c, size_t len) 16 | { 17 | while (len--) 18 | *((unsigned char *)(b + len)) = (unsigned char) c; 19 | return (b); 20 | } 21 | -------------------------------------------------------------------------------- /ft_lstdelone.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstdelone.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/07 06:28:55 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/08 15:42:04 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstdelone(t_list *lst, void (*del)(void *)) 16 | { 17 | if (!lst) 18 | return ; 19 | if (del) 20 | del(lst->content); 21 | free(lst); 22 | } 23 | -------------------------------------------------------------------------------- /ft_lstsize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstsize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/06 18:22:35 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/06 18:23:05 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_lstsize(t_list *lst) 16 | { 17 | int size; 18 | 19 | size = 0; 20 | while (lst) 21 | { 22 | size++; 23 | lst = lst->next; 24 | } 25 | return (size); 26 | } 27 | -------------------------------------------------------------------------------- /ft_calloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_calloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/06 10:39:02 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/06 11:04:13 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_calloc(size_t count, size_t size) 16 | { 17 | void *res; 18 | 19 | res = malloc(size * count); 20 | if (!res) 21 | return (0); 22 | ft_bzero(res, size * count); 23 | return (res); 24 | } 25 | -------------------------------------------------------------------------------- /ft_memchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/06 10:15:46 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/07 07:19:35 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memchr(const void *s, int c, size_t n) 16 | { 17 | while (n--) 18 | { 19 | if (*(unsigned char *)s == (unsigned char)c) 20 | return ((void *)s); 21 | s++; 22 | } 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /ft_lstclear.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstclear.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/07 06:32:05 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/08 12:31:23 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstclear(t_list **lst, void (*del)(void *)) 16 | { 17 | t_list *tmp; 18 | 19 | while (lst && *lst) 20 | { 21 | tmp = (*lst)->next; 22 | ft_lstdelone(*lst, del); 23 | *lst = tmp; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ft_striteri.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmapi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/05 18:03:35 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/07 07:44:13 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_striteri(char *s, void (*f)(unsigned int, char*)) 16 | { 17 | int i; 18 | 19 | if (!s || !f) 20 | return ; 21 | i = 0; 22 | while (s[i]) 23 | { 24 | f(i, &s[i]); 25 | i++; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ft_lstnew.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstnew.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/06 11:42:22 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/06 17:26:03 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstnew(void *content) 16 | { 17 | t_list *new; 18 | 19 | new = malloc(sizeof(t_list)); 20 | if (!new) 21 | return (NULL); 22 | new->next = NULL; 23 | new->content = content; 24 | return (new); 25 | } 26 | -------------------------------------------------------------------------------- /ft_strchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/02 08:44:05 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/10 08:03:05 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strchr(const char *s, int c) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (s[i]) 21 | { 22 | if (s[i] == (char)c) 23 | return ((char *) &s[i]); 24 | i++; 25 | } 26 | if ((char) !c) 27 | return ((char *) &s[i]); 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /ft_strrchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strrchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/02 09:09:54 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/07 09:24:28 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strrchr(const char *s, int c) 16 | { 17 | int i; 18 | 19 | i = ft_strlen(s); 20 | while (i >= 0) 21 | { 22 | if (s[i] == (char)c) 23 | return ((char *) &s[i]); 24 | i--; 25 | } 26 | if (!(char)c) 27 | return ((char *) &s[i]); 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /ft_memcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/06 08:03:24 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/07 10:39:19 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memcpy(void *dst, const void *src, size_t n) 16 | { 17 | size_t i; 18 | 19 | if (!dst && !src) 20 | return (0); 21 | i = 0; 22 | while (i < n) 23 | { 24 | *((unsigned char *)(dst + i)) = *((unsigned char *)(src + i)); 25 | i++; 26 | } 27 | return (dst); 28 | } 29 | -------------------------------------------------------------------------------- /ft_lstadd_back.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_back.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/06 18:47:00 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/08 15:38:45 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_back(t_list **lst, t_list *new) 16 | { 17 | t_list *tmp; 18 | 19 | if (!lst || !new) 20 | return ; 21 | tmp = *lst; 22 | if (*lst) 23 | { 24 | while (tmp->next) 25 | tmp = tmp->next; 26 | tmp->next = new; 27 | } 28 | else 29 | *lst = new; 30 | } 31 | -------------------------------------------------------------------------------- /ft_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/02 13:47:01 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/09 18:10:26 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_strncmp(const char *s1, const char *s2, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | if (!n) 21 | return (0); 22 | while (s1[i] == s2[i] && s1[i] && s2[i] && i < n) 23 | i++; 24 | if (i == n) 25 | return (0); 26 | return ((unsigned char) s1[i] - (unsigned char) s2[i]); 27 | } 28 | -------------------------------------------------------------------------------- /ft_memmove.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memmove.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/06 08:58:22 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/09 15:38:17 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memmove(void *dst, const void *src, size_t len) 16 | { 17 | if (!dst && !src) 18 | return (NULL); 19 | if (dst < src) 20 | ft_memcpy(dst, src, len); 21 | else 22 | { 23 | while (len--) 24 | *((unsigned char *)(dst + len)) = *((unsigned char *)(src + len)); 25 | } 26 | return (dst); 27 | } 28 | -------------------------------------------------------------------------------- /ft_putnbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/05 11:05:32 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/05 12:18:17 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putnbr_fd(int n, int fd) 16 | { 17 | unsigned int nb; 18 | 19 | nb = n; 20 | if (n < 0) 21 | { 22 | ft_putchar_fd('-', fd); 23 | nb *= -1; 24 | } 25 | if (nb < 10) 26 | ft_putchar_fd(nb + '0', fd); 27 | else 28 | { 29 | ft_putnbr_fd(nb / 10, fd); 30 | ft_putnbr_fd(nb % 10, fd); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ft_isalpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/01 17:04:53 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/07 17:13:37 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | static int ft_isupper(int c) 14 | { 15 | if (c >= 'A' && c <= 'Z') 16 | return (1); 17 | return (0); 18 | } 19 | 20 | static int ft_islower(int c) 21 | { 22 | if (c >= 'a' && c <= 'z') 23 | return (1); 24 | return (0); 25 | } 26 | 27 | int ft_isalpha(int c) 28 | { 29 | if (ft_isupper(c) || ft_islower(c)) 30 | return (1); 31 | return (0); 32 | } 33 | -------------------------------------------------------------------------------- /ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/04 13:12:49 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/05 08:06:04 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strdup(const char *s1) 16 | { 17 | char *copy; 18 | size_t s1_len; 19 | int i; 20 | 21 | i = 0; 22 | s1_len = ft_strlen(s1); 23 | copy = malloc(sizeof(char) * (s1_len + 1)); 24 | if (!copy) 25 | return (NULL); 26 | while (s1[i]) 27 | { 28 | copy[i] = s1[i]; 29 | i++; 30 | } 31 | copy[i] = '\0'; 32 | return (copy); 33 | } 34 | -------------------------------------------------------------------------------- /ft_strlcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/03 09:16:12 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/04 12:04:39 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlcpy(char *dst, const char *src, size_t dstsize) 16 | { 17 | size_t src_len; 18 | size_t i; 19 | 20 | i = 0; 21 | src_len = ft_strlen((char *) src); 22 | if (dstsize) 23 | { 24 | while (src[i] && i < dstsize - 1) 25 | { 26 | dst[i] = src[i]; 27 | i++; 28 | } 29 | dst[i] = '\0'; 30 | } 31 | return (src_len); 32 | } 33 | -------------------------------------------------------------------------------- /ft_memcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/06 09:42:29 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/07 10:29:07 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_memcmp(const void *s1, const void *s2, size_t n) 16 | { 17 | unsigned char *x; 18 | unsigned char *y; 19 | size_t i; 20 | 21 | i = 0; 22 | x = (unsigned char *)s1; 23 | y = (unsigned char *)s2; 24 | if (!n) 25 | return (0); 26 | while (i < n) 27 | { 28 | if (x[i] != y[i]) 29 | return (x[i] - y[i]); 30 | i++; 31 | } 32 | return (0); 33 | } 34 | -------------------------------------------------------------------------------- /ft_strmapi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmapi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/05 18:03:35 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/10 09:25:28 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) 16 | { 17 | char *ret; 18 | int len; 19 | int i; 20 | 21 | if (!s || !f) 22 | return (NULL); 23 | i = 0; 24 | len = ft_strlen(s); 25 | ret = malloc(sizeof(char) * (len + 1)); 26 | if (!ret) 27 | return (NULL); 28 | while (s[i]) 29 | { 30 | ret[i] = f(i, s[i]); 31 | i++; 32 | } 33 | ret[i] = '\0'; 34 | return (ret); 35 | } 36 | -------------------------------------------------------------------------------- /ft_lstmap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstmap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/07 06:50:58 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/07 21:09:17 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) 16 | { 17 | t_list *new_lst; 18 | t_list *elem; 19 | 20 | new_lst = NULL; 21 | while (lst && f) 22 | { 23 | elem = ft_lstnew(f(lst->content)); 24 | if (!elem) 25 | { 26 | ft_lstclear(&new_lst, del); 27 | return (NULL); 28 | } 29 | ft_lstadd_back(&new_lst, elem); 30 | lst = lst->next; 31 | } 32 | return (new_lst); 33 | } 34 | -------------------------------------------------------------------------------- /ft_strnstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/02 14:02:49 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/10 07:16:00 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strnstr(const char *haystack, const char *needle, size_t len) 16 | { 17 | size_t i; 18 | size_t nlen; 19 | 20 | if (*needle == 0) 21 | return ((char *) haystack); 22 | i = 0; 23 | nlen = ft_strlen(needle); 24 | while (i < len && haystack[i]) 25 | { 26 | if (haystack[i] == *needle && len - i >= nlen 27 | && ft_strncmp(&haystack[i], needle, nlen) == 0) 28 | return ((char *) &haystack[i]); 29 | i++; 30 | } 31 | return (NULL); 32 | } 33 | -------------------------------------------------------------------------------- /ft_strjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/04 13:51:29 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/06 10:35:45 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strjoin(char const *s1, char const *s2) 16 | { 17 | char *str; 18 | int s1_len; 19 | int s2_len; 20 | int i; 21 | 22 | i = 0; 23 | if (!s1 || !s2) 24 | return (0); 25 | s1_len = ft_strlen(s1); 26 | s2_len = ft_strlen(s2); 27 | str = malloc(sizeof(char) * (s1_len + s2_len + 1)); 28 | if (!str) 29 | return (NULL); 30 | while (s1[i]) 31 | { 32 | str[i] = s1[i]; 33 | i++; 34 | } 35 | i = 0; 36 | while (s2[i]) 37 | str[s1_len++] = s2[i++]; 38 | str[s1_len] = '\0'; 39 | return (str); 40 | } 41 | -------------------------------------------------------------------------------- /ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/03 09:07:25 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/29 17:15:19 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | static int ft_isspace(char c) 14 | { 15 | if (c == ' ' || c == '\t' || c == '\v' 16 | || c == '\r' || c == '\f' || c == '\n') 17 | return (1); 18 | return (0); 19 | } 20 | 21 | int ft_atoi(const char *str) 22 | { 23 | int res; 24 | int sign; 25 | int i; 26 | 27 | i = 0; 28 | sign = 1; 29 | res = 0; 30 | while (ft_isspace(str[i])) 31 | i++; 32 | if (str[i] == '-') 33 | { 34 | sign = -1; 35 | i++; 36 | } 37 | else if (str[i] == '+') 38 | i++; 39 | while (str[i] >= '0' && str[i] <= '9') 40 | res = (res * 10) + (str[i++] - '0'); 41 | return (res * sign); 42 | } 43 | -------------------------------------------------------------------------------- /ft_substr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_substr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/04 13:28:17 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/10 09:19:18 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_substr(char const *s, unsigned int start, size_t len) 16 | { 17 | char *substr; 18 | size_t i; 19 | 20 | i = 0; 21 | if (!s) 22 | return (NULL); 23 | if (start >= ft_strlen(s)) 24 | return ((char *) ft_calloc(1, sizeof(char))); 25 | if (ft_strlen(s) <= start + len) 26 | substr = malloc(sizeof(char) * (ft_strlen(s) - start + 1)); 27 | else 28 | substr = malloc(sizeof(char) * (len + 1)); 29 | if (!substr) 30 | return (NULL); 31 | while (s[start] && i < len) 32 | substr[i++] = s[start++]; 33 | substr[i] = '\0'; 34 | return (substr); 35 | } 36 | -------------------------------------------------------------------------------- /ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/04 09:30:02 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/09 13:23:52 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | static size_t ft_min(size_t x, size_t y) 16 | { 17 | if (x < y) 18 | return (x); 19 | return (y); 20 | } 21 | 22 | size_t ft_strlcat(char *dst, const char *src, size_t dstsize) 23 | { 24 | size_t dst_len; 25 | size_t src_len; 26 | size_t i; 27 | size_t result; 28 | 29 | i = 0; 30 | dst_len = ft_strlen(dst); 31 | src_len = ft_strlen(src); 32 | result = src_len + ft_min(dst_len, dstsize); 33 | if (dstsize == 0) 34 | return (result); 35 | while (src[i] && dst_len + i < dstsize - 1) 36 | { 37 | dst[dst_len + i] = src[i]; 38 | i++; 39 | } 40 | dst[dst_len + i] = '\0'; 41 | return (result); 42 | } 43 | -------------------------------------------------------------------------------- /ft_strtrim.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strtrim.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/05 20:48:14 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/10 09:22:16 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | #include 15 | 16 | static int in_set(char const c, char const *set) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (set[i]) 22 | { 23 | if (c == set[i]) 24 | return (1); 25 | i++; 26 | } 27 | return (0); 28 | } 29 | 30 | char *ft_strtrim(char const *s1, char const *set) 31 | { 32 | int start; 33 | int end; 34 | 35 | if (!s1) 36 | return (NULL); 37 | start = 0; 38 | end = ft_strlen(s1) - 1; 39 | while (s1[start] && in_set(s1[start], set)) 40 | start++; 41 | while (s1[end] && in_set(s1[end], set)) 42 | end--; 43 | if (end == -1) 44 | return (ft_substr(s1, start, 0)); 45 | return (ft_substr(s1, start, (end - start + 1))); 46 | } 47 | -------------------------------------------------------------------------------- /ft_itoa.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_itoa.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/04 17:03:25 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/10 11:20:45 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | static int num_len(int n) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (n) 21 | { 22 | n /= 10; 23 | i++; 24 | } 25 | return (i); 26 | } 27 | 28 | static char *ft_strrev(char *str) 29 | { 30 | char tmp; 31 | int start; 32 | int end; 33 | 34 | start = 0; 35 | end = ft_strlen(str) - 1; 36 | while (start < end) 37 | { 38 | tmp = str[start]; 39 | str[start] = str[end]; 40 | str[end] = tmp; 41 | start++; 42 | end--; 43 | } 44 | return (str); 45 | } 46 | 47 | static void check_negative(int *n, unsigned int *nbr, size_t *nl) 48 | { 49 | if (*n <= 0) 50 | { 51 | *nbr = -(*n); 52 | (*nl)++; 53 | } 54 | } 55 | 56 | char *ft_itoa(int n) 57 | { 58 | char *num; 59 | size_t i; 60 | size_t nl; 61 | unsigned int nbr; 62 | 63 | i = 0; 64 | nl = 0; 65 | nbr = n; 66 | check_negative(&n, &nbr, &nl); 67 | nl += num_len(n); 68 | num = malloc(sizeof(char) * (nl + 1)); 69 | if (!num) 70 | return (NULL); 71 | if (n == 0) 72 | num[i++] = '0'; 73 | while (nbr) 74 | { 75 | num[i++] = (nbr % 10) + '0'; 76 | nbr /= 10; 77 | } 78 | if (n < 0) 79 | num[i++] = '-'; 80 | num[i] = 0; 81 | return (ft_strrev(num)); 82 | } 83 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: ael-khni +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2021/11/04 11:25:09 by ael-khni #+# #+# # 9 | # Updated: 2021/11/10 18:28:30 by ael-khni ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | CC=GCC 14 | FLAGS= -Wall -Werror -Wextra -I libft.h 15 | AR=ar crs 16 | RM=rm -rf 17 | FILES= ft_isalpha ft_isdigit ft_isalnum ft_isascii ft_strlen \ 18 | ft_toupper ft_tolower ft_strchr ft_strrchr ft_strncmp \ 19 | ft_strnstr ft_strlcpy ft_strlcat ft_atoi ft_strdup \ 20 | ft_substr ft_strjoin ft_split ft_itoa ft_strmapi \ 21 | ft_putchar_fd ft_putstr_fd ft_putendl_fd ft_isprint \ 22 | ft_putnbr_fd ft_strtrim ft_memcpy ft_memmove ft_memset \ 23 | ft_memcmp ft_memchr ft_bzero ft_calloc ft_striteri 24 | BFILES = ft_lstnew ft_lstadd_front \ 25 | ft_striteri ft_lstsize ft_lstlast ft_lstadd_back ft_lstdelone \ 26 | ft_lstclear ft_lstiter ft_lstmap 27 | OBJ=$(FILES:=.o) 28 | BOBJ=$(BFILES:=.o) 29 | NAME=libft.a 30 | 31 | RED = \033[1;31m 32 | GREEN = \033[1;32m 33 | YELLOW = \033[1;33m 34 | BLUE = \033[1;34m 35 | RESET = \033[0m 36 | 37 | .PHONY: all bonus clean fclean re 38 | 39 | all: $(NAME) 40 | @echo "$(RED)------safi done------$(RESET)" 41 | 42 | 43 | bonus: all $(BOBJ) 44 | echo "hani kan commpili $(GREEN)" $< "$(RESET)akhay sat" 45 | @$(AR) $(NAME) $(BOBJ) 46 | 47 | $(NAME): $(OBJ) 48 | @$(AR) $(NAME) $(OBJ) 49 | 50 | %.o: %.c libft.h 51 | @echo "hani kan commpili$(GREEN)" $< "$(RESET)akhay sat" 52 | @$(CC) $(FLAGS) -c $< -o $@ 53 | 54 | clean: 55 | @echo "$(YELLOW)Cleaned$(RESET)" 56 | @$(RM) $(OBJ) $(BOBJ) 57 | 58 | fclean: clean 59 | @$(RM) $(NAME) 60 | 61 | re: fclean all 62 | -------------------------------------------------------------------------------- /ft_split.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_split.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/04 14:13:19 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/10 08:16:15 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | static char **malloc_error(char **tab) 16 | { 17 | unsigned int i; 18 | 19 | i = 0; 20 | while (tab[i]) 21 | free(tab[i++]); 22 | free(tab); 23 | return (NULL); 24 | } 25 | 26 | static int word_count(const char *str, char c) 27 | { 28 | int i; 29 | int count; 30 | 31 | i = 0; 32 | count = 0; 33 | while (str[i]) 34 | { 35 | if (str[i] == c) 36 | i++; 37 | else 38 | { 39 | count++; 40 | while (str[i] != c && str[i]) 41 | i++; 42 | } 43 | } 44 | return (count); 45 | } 46 | 47 | static char *ft_getword(const char *s1, int *index, char c) 48 | { 49 | char *copy; 50 | size_t word_len; 51 | int i; 52 | 53 | word_len = 0; 54 | while (s1[*index] == c) 55 | (*index)++; 56 | i = *index; 57 | while (s1[i] && s1[i] != c) 58 | { 59 | word_len++; 60 | i++; 61 | } 62 | copy = malloc(sizeof(char) * (word_len + 1)); 63 | if (!copy) 64 | return (NULL); 65 | i = 0; 66 | while (s1[*index] && s1[*index] != c) 67 | copy[i++] = s1[(*index)++]; 68 | copy[i] = '\0'; 69 | return (copy); 70 | } 71 | 72 | char **ft_split(char const *s, char c) 73 | { 74 | char **arr; 75 | int index; 76 | int wc; 77 | int i; 78 | 79 | index = 0; 80 | i = 0; 81 | if (!s) 82 | return (NULL); 83 | wc = word_count(s, c); 84 | arr = malloc(sizeof(char *) * (wc + 1)); 85 | if (!arr) 86 | return (NULL); 87 | while (i < wc) 88 | { 89 | arr[i] = ft_getword(s, &index, c); 90 | if (!arr[i]) 91 | return (malloc_error(arr)); 92 | i++; 93 | } 94 | arr[i] = 0; 95 | return (arr); 96 | } 97 | -------------------------------------------------------------------------------- /libft.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* libft.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ael-khni +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/04 10:49:44 by ael-khni #+# #+# */ 9 | /* Updated: 2021/11/10 16:37:03 by ael-khni ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LIBFT_H 14 | # define LIBFT_H 15 | 16 | # include 17 | # include 18 | 19 | /* Mandatory part */ 20 | 21 | int ft_isalpha(int c); 22 | int ft_isdigit(int c); 23 | int ft_isalnum(int c); 24 | int ft_isascii(int c); 25 | int ft_isprint(int c); 26 | size_t ft_strlen(const char *s); 27 | int ft_toupper(int c); 28 | int ft_tolower(int c); 29 | char *ft_strchr(const char *s, int c); 30 | char *ft_strrchr(const char *s, int c); 31 | int ft_strncmp(const char *s1, const char *s2, size_t n); 32 | char *ft_strnstr(const char *haystack, const char *needle, size_t len); 33 | size_t ft_strlcpy(char *dst, const char *src, size_t dstsize); 34 | size_t ft_strlcat(char *dst, const char *src, size_t dstsize); 35 | int ft_atoi(const char *str); 36 | void *ft_memset(void *b, int c, size_t len); 37 | void ft_bzero(void *s, size_t n); 38 | void *ft_memcpy(void *dst, const void *src, size_t n); 39 | void *ft_memmove(void *dst, const void *src, size_t len); 40 | void *ft_memchr(const void *s, int c, size_t n); 41 | int ft_memcmp(const void *s1, const void *s2, size_t n); 42 | void *ft_calloc(size_t count, size_t size); 43 | char *ft_strdup(const char *s1); 44 | 45 | /* Additional funcitons */ 46 | 47 | char *ft_substr(char const *s, unsigned int start, size_t len); 48 | char *ft_strjoin(char const *s1, char const *s2); 49 | char *ft_strtrim(char const *s1, char const *set); 50 | char **ft_split(char const *s, char c); 51 | char *ft_itoa(int n); 52 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); 53 | void ft_striteri(char *s, void (*f)(unsigned int, char*)); 54 | void ft_putchar_fd(char c, int fd); 55 | void ft_putstr_fd(char *s, int fd); 56 | void ft_putendl_fd(char *s, int fd); 57 | void ft_putnbr_fd(int n, int fd); 58 | 59 | typedef struct s_list 60 | { 61 | void *content; 62 | struct s_list *next; 63 | } t_list; 64 | 65 | int ft_lstsize(t_list *lst); 66 | t_list *ft_lstlast(t_list *lst); 67 | t_list *ft_lstnew(void *content); 68 | void ft_lstadd_front(t_list **lst, t_list *new); 69 | void ft_lstadd_back(t_list **lst, t_list *new); 70 | void ft_lstiter(t_list *lst, void (*f)(void *)); 71 | void ft_lstdelone(t_list *lst, void (*del)(void *)); 72 | void ft_lstclear(t_list **lst, void (*del)(void *)); 73 | t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)); 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 42cursus' libft 3 |

4 | 5 |

6 | Development repo for 42cursus' libft project
7 | For further information about 42cursus and its projects, please refer to 42cursus repo. 8 |

9 | 10 |

11 | About 12 | · 13 | Testing 14 |

15 | 16 | --- 17 | 18 | ## 🗣️ About 19 | 20 | > _The aim of this project is to code a C library regrouping usual functions that you'll be allowed to use in all your other projects._ 21 | 22 | 🚀 TLDR: this project consists of coding basic C functions (see below), which are then compiled 23 | into a library for use in other projects of the cursus. 24 | 25 | ### Functions from `` library 26 | 27 | * [`ft_isascii`](ft_isascii.c) - test for ASCII character. 28 | * [`ft_isalnum`](ft_isalnum.c) - alphanumeric character test. 29 | * [`ft_isalpha`](ft_isalpha.c) - alphabetic character test. 30 | * [`ft_isdigit`](ft_isdigit.c) - decimal-digit character test. 31 | * [`ft_isprint`](ft_isprint.c) - printing character test (space character inclusive). 32 | * [`ft_tolower`](ft_tolower.c) - upper case to lower case letter conversion. 33 | * [`ft_toupper`](ft_toupper.c) - lower case to upper case letter conversion. 34 | 35 | ### Functions from `` library 36 | 37 | * [`ft_atoi`](ft_atoi.c) - convert ASCII string to integer. 38 | * [`ft_calloc`](ft_calloc.c) - memory allocation. 39 | 40 | ### Functions from `` library 41 | 42 | * [`ft_bzero`](ft_bzero.c) - write zeroes to a byte string. 43 | * [`ft_memset`](ft_memset.c) - write a byte to a byte string. 44 | * [`ft_memchr`](ft_memchr.c) - locate byte in byte string. 45 | * [`ft_memcmp`](ft_memcmp.c) - compare byte string. 46 | * [`ft_memmove`](ft_memmove.c) - copy byte string. 47 | * [`ft_memcpy`](ft_memcpy.c) - copy memory area. 48 | * [`ft_memccpy`](ft_memccpy.c) - copy string until character found. 49 | 50 | ### Functions from `` library 51 | 52 | * [`ft_strlen`](ft_strlen.c) - find length of string. 53 | * [`ft_strchr`](ft_strchr.c) - locate character in string (first occurrence). 54 | * [`ft_strrchr`](ft_strrchr.c) - locate character in string (last occurence). 55 | * [`ft_strnstr`](ft_strnstr.c) - locate a substring in a string (size-bounded). 56 | * [`ft_strncmp`](ft_strncmp.c) - compare strings (size-bounded). 57 | * [`ft_strnrcmp`](ft_strnrcmp.c) - reversely compare strings (size-bounded). 58 | * [`ft_strdup`](ft_strdup.c) - save a copy of a string (with malloc). 59 | * [`ft_strlcpy`](ft_strlcpy.c) - size-bounded string copying. 60 | * [`ft_strlcat`](ft_strlcat.c) - size-bounded string concatenation. 61 | 62 | ### Non-standard functions 63 | 64 | * [`ft_putchar_fd`](ft_putchar_fd.c) - output a character to given file. 65 | * [`ft_putstr_fd`](ft_putstr_fd.c) - output string to given file. 66 | * [`ft_putendl_fd`](ft_putendl_fd.c) - output string to given file with newline. 67 | * [`ft_putnbr_fd`](ft_putnbr_fd.c) - output integer to given file. 68 | * [`ft_itoa`](ft_itoa.c) - convert integer to ASCII string. 69 | * [`ft_substr`](ft_substr.c) - extract substring from string. 70 | * [`ft_strtrim`](ft_strtrim.c) - trim beginning and end of string with the specified characters. 71 | * [`ft_strjoin`](ft_strjoin.c) - concatenate two strings into a new string (with malloc). 72 | * [`ft_split`](ft_split.c) - split string, with specified character as delimiter, into an array of strings. 73 | * [`ft_strmapi`](ft_strmapi.c) - create new string from modifying string with specified function. 74 | 75 | ### Linked list functions 76 | 77 | * [`ft_lstnew`](ft_lstnew.c) - create new list. 78 | * [`ft_lstsize`](ft_lstsize.c) - count elements of a list. 79 | * [`ft_lstlast`](ft_lstlast.c) - find last element of list. 80 | * [`ft_lstadd_back`](ft_lstadd_back.c) - add new element at end of list. 81 | * [`ft_lstadd_front`](ft_lstadd_front.c) - add new element at beginning of list. 82 | * [`ft_lstdelone`](ft_lstdelone.c) - delete element from list. 83 | * [`ft_lstclear`](ft_lstclear.c) - delete sequence of elements of list from a starting point. 84 | * [`ft_lstiter`](ft_lstiter.c) - apply function to content of all list's elements. 85 | * [`ft_lstmap`](ft_lstmap.c) - apply function to content of all list's elements into new list. 86 | 87 | _Note: functions marked with * are bonus functions (not mandatory by the project's subject)._ 88 | 89 | ### Third-party testers 90 | 91 | * [jtoty/Libftest](https://github.com/jtoty/Libftest) 92 | * [alelievr/libft-unit-test](https://github.com/alelievr/libft-unit-test) 93 | * [Night-squad/libft-war-machine-v2019](https://github.com/Night-squad/libft-war-machine-v2019) 94 | * [t0mm4rx/libftdestructor](https://github.com/t0mm4rx/libftdestructor) 95 | --------------------------------------------------------------------------------