├── a.out ├── ft_putchar_fd.c ├── ft_tolower.c ├── ft_toupper.c ├── ft_isprint.c ├── ft_isascii.c ├── ft_isdigit.c ├── ft_lstadd_front.c ├── ft_lstlast.c ├── ft_strlen.c ├── ft_isalpha.c ├── ft_lstdelone.c ├── ft_putstr_fd.c ├── ft_lstiter.c ├── ft_isalnum.c ├── ft_lstsize.c ├── ft_putendl_fd.c ├── ft_striteri.c ├── ft_bzero.c ├── ft_memset.c ├── ft_calloc.c ├── ft_lstadd_back.c ├── ft_lstclear.c ├── ft_memcpy.c ├── ft_memchr.c ├── ft_strlcpy.c ├── ft_strchr.c ├── ft_strdup.c ├── ft_strrchr.c ├── ft_strncmp.c ├── ft_memcmp.c ├── ft_putnbr_fd.c ├── ft_strlcat.c ├── ft_strmapi.c ├── ft_atoi.c ├── ft_strnstr.c ├── ft_memmove.c ├── ft_strjoin.c ├── ft_lstnew.c ├── ft_lstmap.c ├── ft_substr.c ├── ft_itoa.c ├── ft_strtrim.c ├── ft_split.c ├── Makefile └── libft.h /a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mousstache/libft/HEAD/a.out -------------------------------------------------------------------------------- /ft_putchar_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/09 19:54:54 by motroian #+# #+# */ 9 | /* Updated: 2022/11/09 21:10:43 by motroian ### ########.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: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 14:50:41 by motroian #+# #+# */ 9 | /* Updated: 2022/11/11 18:28:10 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_tolower(int c) 16 | { 17 | if (c >= 'A' && c <= 'Z') 18 | c += 32; 19 | return (c); 20 | } 21 | -------------------------------------------------------------------------------- /ft_toupper.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_toupper.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 14:50:57 by motroian #+# #+# */ 9 | /* Updated: 2022/11/11 18:59:11 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_toupper(int c) 16 | { 17 | if (c >= 'a' && c <= 'z') 18 | c -= 32; 19 | return (c); 20 | } 21 | -------------------------------------------------------------------------------- /ft_isprint.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isprint.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 14:11:52 by motroian #+# #+# */ 9 | /* Updated: 2022/11/11 19:21:47 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isprint(int nb) 16 | { 17 | if (nb < 32 || nb > 126) 18 | return (0); 19 | return (1); 20 | } 21 | -------------------------------------------------------------------------------- /ft_isascii.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isascii.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/09 18:00:50 by motroian #+# #+# */ 9 | /* Updated: 2022/11/11 19:26:02 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isascii(int nb) 16 | { 17 | if (!(nb >= 0 && nb <= 127)) 18 | return (0); 19 | return (1); 20 | } 21 | -------------------------------------------------------------------------------- /ft_isdigit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isdigit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 14:12:53 by motroian #+# #+# */ 9 | /* Updated: 2022/11/09 19:22:04 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isdigit(int nb) 16 | { 17 | if (!(nb >= '0' && nb <= '9')) 18 | return (0); 19 | return (1); 20 | } 21 | -------------------------------------------------------------------------------- /ft_lstadd_front.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_front.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/10 17:15:09 by motroian #+# #+# */ 9 | /* Updated: 2022/11/18 21:29:04 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_front(t_list **lst, t_list *new) 16 | { 17 | if (*lst) 18 | new->next = *lst; 19 | *lst = new; 20 | } 21 | -------------------------------------------------------------------------------- /ft_lstlast.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstlast.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/10 17:16:05 by motroian #+# #+# */ 9 | /* Updated: 2022/11/18 21:15:16 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstlast(t_list *lst) 16 | { 17 | while (lst && lst->next != NULL) 18 | lst = lst->next; 19 | return (lst); 20 | } 21 | -------------------------------------------------------------------------------- /ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/09 18:02:47 by motroian #+# #+# */ 9 | /* Updated: 2022/11/19 17:00:34 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlen(const char *s) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (s[i]) 21 | i++; 22 | return (i); 23 | } 24 | -------------------------------------------------------------------------------- /ft_isalpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 14:11:40 by motroian #+# #+# */ 9 | /* Updated: 2022/11/11 19:28:28 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isalpha(int nb) 16 | { 17 | if ((nb >= 'a' && nb <= 'z') || (nb >= 'A' && nb <= 'Z')) 18 | return (1); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /ft_lstdelone.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstdelone.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/10 17:14:35 by motroian #+# #+# */ 9 | /* Updated: 2022/11/18 21:18:55 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstdelone(t_list *lst, void (*del)(void*)) 16 | { 17 | if (lst) 18 | { 19 | (*del)(lst->content); 20 | free(lst); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ft_putstr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/09 21:10:51 by motroian #+# #+# */ 9 | /* Updated: 2022/11/12 16:48:20 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putstr_fd(char *s, int fd) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (s[i]) 21 | { 22 | write(fd, &s[i], 1); 23 | i++; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ft_lstiter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstiter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/10 17:15:44 by motroian #+# #+# */ 9 | /* Updated: 2022/11/17 21:40:45 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstiter(t_list *lst, void (*f)(void *)) 16 | { 17 | while (lst && lst != NULL) 18 | { 19 | (*f)(lst->content); 20 | lst = lst->next; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ft_isalnum.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalnum.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 14:12:40 by motroian #+# #+# */ 9 | /* Updated: 2022/11/17 13:21:34 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isalnum(int nb) 16 | { 17 | if ((nb >= 'a' && nb <= 'z') || (nb >= 'A' && nb <= 'Z') 18 | || (nb >= '0' && nb <= '9')) 19 | return (1); 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /ft_lstsize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstsize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/10 17:15:33 by motroian #+# #+# */ 9 | /* Updated: 2022/11/18 21:16:44 by motroian ### ########.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 | lst = lst->next; 23 | size++; 24 | } 25 | return (size); 26 | } 27 | -------------------------------------------------------------------------------- /ft_putendl_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putendl_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/09 23:15:26 by motroian #+# #+# */ 9 | /* Updated: 2022/11/12 18:47:37 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putendl_fd(char *s, int fd) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (s[i]) 21 | { 22 | write(fd, &s[i], 1); 23 | i++; 24 | } 25 | write(fd, "\n", 1); 26 | } 27 | -------------------------------------------------------------------------------- /ft_striteri.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_striteri.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/10 17:05:15 by motroian #+# #+# */ 9 | /* Updated: 2022/11/10 19:33:11 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_striteri(char *s, void (*f)(unsigned int, char*)) 16 | { 17 | unsigned int i; 18 | 19 | i = 0; 20 | while (s[i]) 21 | { 22 | (*f)(i, &s[i]); 23 | i++; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ft_bzero.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_bzero.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 20:08:49 by motroian #+# #+# */ 9 | /* Updated: 2022/11/09 19:24:45 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_bzero(void *s, size_t n) 16 | { 17 | char *s2; 18 | int i; 19 | 20 | s2 = (char *)s; 21 | i = 0; 22 | while (n > 0) 23 | { 24 | s2[i] = '\0'; 25 | i++; 26 | n--; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ft_memset.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memset.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 17:50:42 by motroian #+# #+# */ 9 | /* Updated: 2022/11/09 19:26:34 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memset(void *s, int c, size_t n) 16 | { 17 | unsigned char *s2; 18 | 19 | s2 = (unsigned char *)s; 20 | while (n--) 21 | { 22 | *s2 = c; 23 | s2++; 24 | } 25 | return (s); 26 | } 27 | -------------------------------------------------------------------------------- /ft_calloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_calloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/10 17:10:11 by motroian #+# #+# */ 9 | /* Updated: 2022/11/22 17:53:32 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_calloc(size_t nmemb, size_t size) 16 | { 17 | char *str; 18 | 19 | str = malloc(nmemb * size); 20 | if (!str) 21 | return (0); 22 | ft_bzero(str, nmemb * size); 23 | return (str); 24 | } 25 | -------------------------------------------------------------------------------- /ft_lstadd_back.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_back.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/10 17:15:18 by motroian #+# #+# */ 9 | /* Updated: 2022/11/18 21:20:28 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_back(t_list **lst, t_list *new) 16 | { 17 | t_list *last; 18 | 19 | if (*lst == NULL) 20 | *lst = new; 21 | else 22 | { 23 | last = ft_lstlast(*lst); 24 | last->next = new; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ft_lstclear.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstclear.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/10 17:14:48 by motroian #+# #+# */ 9 | /* Updated: 2022/11/18 21:21:15 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstclear(t_list **lst, void (*del)(void*)) 16 | { 17 | t_list *list; 18 | t_list *tmp; 19 | 20 | list = *lst; 21 | while (list) 22 | { 23 | (*del)(list->content); 24 | tmp = list->next; 25 | free(list); 26 | list = tmp; 27 | } 28 | *lst = NULL; 29 | } 30 | -------------------------------------------------------------------------------- /ft_memcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 17:51:13 by motroian #+# #+# */ 9 | /* Updated: 2022/11/19 21:46:31 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memcpy(void *dest, const void *src, size_t n) 16 | { 17 | char *dest2; 18 | char *src2; 19 | int i; 20 | 21 | src2 = (char *)src; 22 | dest2 = (char *)dest; 23 | i = 0; 24 | while (n > 0) 25 | { 26 | dest2[i] = src2[i]; 27 | i++; 28 | n--; 29 | } 30 | return (dest); 31 | } 32 | -------------------------------------------------------------------------------- /ft_memchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 21:00:25 by motroian #+# #+# */ 9 | /* Updated: 2022/11/18 19:46:28 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memchr(const void *s, int c, size_t n) 16 | { 17 | unsigned char *str; 18 | 19 | if (!s) 20 | return (NULL); 21 | str = (unsigned char *)s; 22 | while (str && n > 0) 23 | { 24 | if ((*str) == (unsigned char)c) 25 | return ((void *)str); 26 | n--; 27 | str++; 28 | } 29 | return (NULL); 30 | } 31 | -------------------------------------------------------------------------------- /ft_strlcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 20:24:58 by motroian #+# #+# */ 9 | /* Updated: 2022/11/19 17:05:08 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlcpy(char *dst, const char *src, size_t size) 16 | { 17 | size_t i; 18 | size_t x; 19 | 20 | x = ft_strlen(src); 21 | i = 0; 22 | if (size != 0) 23 | { 24 | while (src [i] != '\0' && i < size - 1) 25 | { 26 | dst[i] = src[i]; 27 | i++; 28 | } 29 | dst[i] = '\0'; 30 | } 31 | return (x); 32 | } 33 | -------------------------------------------------------------------------------- /ft_strchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 20:23:25 by motroian #+# #+# */ 9 | /* Updated: 2022/11/20 19:56:33 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strchr(const char *s, int c) 16 | { 17 | char *s1; 18 | int i; 19 | 20 | s1 = (char *)s; 21 | if (!s) 22 | return (NULL); 23 | i = ft_strlen(s); 24 | if (c == '\0') 25 | return (&s1[i]); 26 | i = 0; 27 | while (s1[i]) 28 | { 29 | if (s1[i] == (char)c) 30 | return (&s1[i]); 31 | i++; 32 | } 33 | return (0); 34 | } 35 | -------------------------------------------------------------------------------- /ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 14:13:34 by motroian #+# #+# */ 9 | /* Updated: 2022/11/20 19:54:23 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strdup(const char *str) 16 | { 17 | size_t i; 18 | size_t slen; 19 | char *dup; 20 | 21 | i = 0; 22 | slen = ft_strlen(str); 23 | dup = malloc(sizeof(char) * (slen + 1)); 24 | if (!dup) 25 | return (0); 26 | while (str[i]) 27 | { 28 | dup[i] = str[i]; 29 | i++; 30 | } 31 | dup[i] = '\0'; 32 | return (dup); 33 | } 34 | -------------------------------------------------------------------------------- /ft_strrchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strrchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 20:45:15 by motroian #+# #+# */ 9 | /* Updated: 2022/11/19 19:41:34 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strrchr(const char *s, int c) 16 | { 17 | char *s1; 18 | size_t j; 19 | int i; 20 | 21 | s1 = (char *)s; 22 | if (!s) 23 | return (NULL); 24 | j = ft_strlen(s); 25 | i = 0; 26 | if (c == '\0') 27 | return ((char *)&s[j]); 28 | i = ft_strlen(s); 29 | i--; 30 | while (i >= 0) 31 | { 32 | if (s1[i] == (char)c) 33 | return (&s1[i]); 34 | i--; 35 | } 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /ft_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 14:50:24 by motroian #+# #+# */ 9 | /* Updated: 2022/11/19 17:06:01 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_strncmp(const char *s1, const char *s2, size_t n) 16 | { 17 | unsigned char *str1; 18 | unsigned char *str2; 19 | int i; 20 | 21 | str1 = (unsigned char *)s1; 22 | str2 = (unsigned char *)s2; 23 | i = 0; 24 | while (n > 0 && s1[i] == s2[i] && s1[i] != '\0' && s2[i] != '\0') 25 | { 26 | n--; 27 | i++; 28 | } 29 | if (n == 0) 30 | return (0); 31 | return (str1[i] - str2[i]); 32 | } 33 | -------------------------------------------------------------------------------- /ft_memcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 19:02:21 by motroian #+# #+# */ 9 | /* Updated: 2022/11/20 19:52:35 by motroian ### ########.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 *str1; 18 | unsigned char *str2; 19 | size_t i; 20 | 21 | if (!s1 || !s2) 22 | return (0); 23 | str1 = (unsigned char *)s1; 24 | str2 = (unsigned char *)s2; 25 | i = 0; 26 | while (n > 0 && str1[i] == str2[i]) 27 | { 28 | n--; 29 | i++; 30 | } 31 | if (n == 0) 32 | return (0); 33 | return (str1[i] - str2[i]); 34 | } 35 | -------------------------------------------------------------------------------- /ft_putnbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/09 21:22:13 by motroian #+# #+# */ 9 | /* Updated: 2022/11/12 20:08:33 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putnbr_fd(int n, int fd) 16 | { 17 | if (n == -2147483648) 18 | { 19 | write(fd, "-2147483648", 11); 20 | } 21 | else if (n < 0) 22 | { 23 | write(fd, "-", 1); 24 | ft_putnbr_fd(n * -1, fd); 25 | } 26 | else if (n >= 0 && n <= 9) 27 | { 28 | n = n + '0'; 29 | write(fd, &n, 1); 30 | } 31 | else if (n > 9) 32 | { 33 | ft_putnbr_fd(n / 10, fd); 34 | ft_putnbr_fd(n % 10, fd); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 14:13:48 by motroian #+# #+# */ 9 | /* Updated: 2022/11/19 17:05:40 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlcat(char *dst, const char *src, size_t size) 16 | { 17 | size_t i; 18 | size_t j; 19 | 20 | i = 0; 21 | while (i < size && dst[i]) 22 | i++; 23 | j = i + ft_strlen(src); 24 | dst += i; 25 | if (size != i) 26 | { 27 | while (*src) 28 | { 29 | if (size > i + 1) 30 | { 31 | *dst++ = *src; 32 | size--; 33 | } 34 | src++; 35 | } 36 | *dst = 0; 37 | } 38 | return (j); 39 | } 40 | -------------------------------------------------------------------------------- /ft_strmapi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmapi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/10 17:04:57 by motroian #+# #+# */ 9 | /* Updated: 2022/11/20 19:08:01 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) 16 | { 17 | unsigned int i; 18 | unsigned int j; 19 | char *cpy; 20 | 21 | if (!s) 22 | return (ft_strdup("")); 23 | cpy = malloc(sizeof(char) * ft_strlen(s) + 1); 24 | if (!cpy) 25 | return (0); 26 | i = 0; 27 | j = 0; 28 | while (s[i]) 29 | { 30 | cpy[j] = (*f)(i, s[i]); 31 | i++; 32 | j++; 33 | } 34 | cpy[j] = '\0'; 35 | return (cpy); 36 | } 37 | -------------------------------------------------------------------------------- /ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 14:12:25 by motroian #+# #+# */ 9 | /* Updated: 2022/11/18 17:20:04 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_atoi(const char *str) 16 | { 17 | int i; 18 | int j; 19 | int k; 20 | 21 | i = 0; 22 | j = 0; 23 | k = 0; 24 | while ((str[i] >= 9 && str[i] <= 13) || (str[i] == 32)) 25 | i++; 26 | if (str[i] == '-' || str[i] == '+') 27 | { 28 | if (str[i] == '-') 29 | j++; 30 | i++; 31 | } 32 | while (str[i] >= '0' && str[i] <= '9') 33 | { 34 | k = k * 10 + (str[i] - '0'); 35 | i++; 36 | } 37 | if (j == 1) 38 | return (k * -1); 39 | return (k); 40 | } 41 | -------------------------------------------------------------------------------- /ft_strnstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/10 17:02:04 by motroian #+# #+# */ 9 | /* Updated: 2022/11/19 20:13:21 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strnstr(const char *big, const char *little, size_t len) 16 | { 17 | size_t i; 18 | size_t j; 19 | 20 | if (*(little) == 0) 21 | return ((char *)(big)); 22 | if (len == 0) 23 | return (NULL); 24 | i = 0; 25 | while (big[i] && i < len) 26 | { 27 | j = 0; 28 | while ((big[i + j]) && (big[i + j] == little[j]) && (i + j < len)) 29 | j++; 30 | if (little[j] == 0) 31 | return ((char *)(big + i)); 32 | i++; 33 | } 34 | return (NULL); 35 | } 36 | -------------------------------------------------------------------------------- /ft_memmove.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memmove.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/10 17:02:28 by motroian #+# #+# */ 9 | /* Updated: 2022/11/13 18:43:41 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memmove(void *dest, const void *src, size_t n) 16 | { 17 | char *dest2; 18 | char *src2; 19 | size_t i; 20 | 21 | dest2 = (char *)dest; 22 | src2 = (char *)src; 23 | i = 0; 24 | if (!dest && !src) 25 | return (dest); 26 | if (dest2 > src2) 27 | { 28 | while (n--) 29 | dest2[n] = src2[n]; 30 | } 31 | else 32 | { 33 | i = 0; 34 | while (n > 0) 35 | { 36 | dest2[i] = src2[i]; 37 | i++; 38 | n--; 39 | } 40 | } 41 | return (dest); 42 | } 43 | -------------------------------------------------------------------------------- /ft_strjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 14:14:27 by motroian #+# #+# */ 9 | /* Updated: 2022/11/29 18:52:37 by motroian ### ########.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 i; 19 | int j; 20 | 21 | str = malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1)); 22 | if (!str) 23 | return (NULL); 24 | i = 0; 25 | j = 0; 26 | while (s1[i]) 27 | { 28 | str[j++] = s1[i++]; 29 | } 30 | i = 0; 31 | while (s2[i]) 32 | { 33 | str[j] = s2[i]; 34 | i++; 35 | j++; 36 | } 37 | str[j] = '\0'; 38 | return (str); 39 | } 40 | int main () 41 | { 42 | printf("%s", ft_strjoin("dd", "kk")); 43 | } 44 | -------------------------------------------------------------------------------- /ft_lstnew.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstnew.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/10 17:14:19 by motroian #+# #+# */ 9 | /* Updated: 2022/11/18 21:18:10 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstnew(void *cont) 16 | { 17 | t_list *retour; 18 | 19 | retour = malloc(sizeof(t_list)); 20 | if (!retour) 21 | return (NULL); 22 | retour->content = cont; 23 | retour->next = NULL; 24 | return (retour); 25 | } 26 | /* 27 | int main(void) 28 | { 29 | char *str = "bonjour"; 30 | char *s = "chien"; 31 | t_list *elem; 32 | 33 | elem = ft_lstnew((void *)str); 34 | elem->next = ft_lstnew((void *)s); 35 | printf("%s\n",(char *) elem->content); 36 | printf("%s\n",(char *) elem->next->content); 37 | }*/ 38 | -------------------------------------------------------------------------------- /ft_lstmap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstmap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/10 17:15:55 by motroian #+# #+# */ 9 | /* Updated: 2022/11/19 16:02:05 by motroian ### ########.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 *list; 18 | t_list *tmp; 19 | 20 | if (!f || !del) 21 | return (NULL); 22 | list = NULL; 23 | while (lst && lst != NULL) 24 | { 25 | tmp = ft_lstnew((*f)(lst->content)); 26 | if (!tmp) 27 | { 28 | while (list) 29 | { 30 | tmp = list->next; 31 | (*del)(list->content); 32 | free(list); 33 | list = tmp; 34 | } 35 | lst = NULL; 36 | } 37 | ft_lstadd_back(&list, tmp); 38 | lst = lst->next; 39 | } 40 | return (list); 41 | } 42 | -------------------------------------------------------------------------------- /ft_substr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_substr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/10 17:04:30 by motroian #+# #+# */ 9 | /* Updated: 2022/11/28 20:18:35 by motroian ### ########.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 *str; 18 | size_t i; 19 | size_t j; 20 | 21 | if (!s) 22 | return (NULL); 23 | if (len > ft_strlen(s) - start) 24 | len = ft_strlen(s) - start; 25 | if (start > ft_strlen(s)) 26 | return (ft_strdup("")); 27 | str = malloc(sizeof(char) * (len + 1)); 28 | if (!str) 29 | return (NULL); 30 | j = 0; 31 | i = start; 32 | while (len > 0 && s[i]) 33 | { 34 | str[j] = s[i]; 35 | j++; 36 | i++; 37 | len--; 38 | } 39 | str[j] = '\0'; 40 | return (str); 41 | } 42 | -------------------------------------------------------------------------------- /ft_itoa.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_itoa.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/08 14:21:28 by motroian #+# #+# */ 9 | /* Updated: 2022/11/21 18:43:52 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int digit_count(int n) 16 | { 17 | int i; 18 | 19 | i = 1; 20 | if (n < 0) 21 | { 22 | n *= -1; 23 | i++; 24 | } 25 | if (n < 0) 26 | i--; 27 | while (n >= 10) 28 | { 29 | n /= 10; 30 | i++; 31 | } 32 | return (i); 33 | } 34 | 35 | char *ft_itoa(int n) 36 | { 37 | char *res; 38 | int i; 39 | int j; 40 | 41 | if (n == -2147483648) 42 | return (ft_strdup("-2147483648")); 43 | i = digit_count(n) - 1; 44 | j = digit_count(n); 45 | res = malloc(sizeof(char) * (digit_count(n) + 1)); 46 | if (!res) 47 | return (NULL); 48 | if (n < 0) 49 | { 50 | res[0] = '-'; 51 | n *= -1; 52 | } 53 | while (n > 9) 54 | { 55 | res[i] = (n % 10) + '0'; 56 | n /= 10; 57 | i--; 58 | } 59 | res[i] = (n % 10) + '0'; 60 | res[j] = '\0'; 61 | return (res); 62 | } 63 | -------------------------------------------------------------------------------- /ft_strtrim.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strtrim.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/10 17:04:43 by motroian #+# #+# */ 9 | /* Updated: 2022/11/18 21:11:32 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_setcheck(char c, char const *set) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (set[i]) 21 | { 22 | if (set[i++] == c) 23 | return (1); 24 | } 25 | return (0); 26 | } 27 | 28 | char *ft_strtrim(char const *s1, char const *set) 29 | { 30 | char *str; 31 | int start; 32 | int end; 33 | int i; 34 | 35 | i = 0; 36 | start = 0; 37 | if (s1 == 0 || set == 0) 38 | return (0); 39 | end = (int)ft_strlen(s1); 40 | while (s1[start] && ft_setcheck(s1[start], set)) 41 | start++; 42 | while (end > start && ft_setcheck(s1[end - 1], set)) 43 | end--; 44 | str = (char *)malloc(sizeof(char) * (end - start + 1)); 45 | if (!str) 46 | return (0); 47 | while (start < end) 48 | { 49 | str[i] = s1[start]; 50 | i++; 51 | start++; 52 | } 53 | str[i] = '\0'; 54 | return (str); 55 | } 56 | -------------------------------------------------------------------------------- /ft_split.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_split.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/15 19:04:27 by motroian #+# #+# */ 9 | /* Updated: 2022/11/22 16:19:43 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_strtab(char *str, char c) 16 | { 17 | int i; 18 | int j; 19 | 20 | i = 0; 21 | j = 1; 22 | while (str[i]) 23 | { 24 | if ((str[i] == c) && (i != 0) && (str[i - 1] != c)) 25 | j++; 26 | i++; 27 | } 28 | return (j); 29 | } 30 | 31 | int ft_slen(char *str, char c) 32 | { 33 | int i; 34 | 35 | i = 0; 36 | while (str[i]) 37 | { 38 | if (str[i] == c) 39 | break ; 40 | i++; 41 | } 42 | return (i); 43 | } 44 | 45 | char **ft_free(char **tab, int j) 46 | { 47 | while (j) 48 | free(tab[j--]); 49 | free (tab); 50 | return (NULL); 51 | } 52 | 53 | char **ft_decoupe(char **tab, char *str, int k, char c) 54 | { 55 | int i; 56 | int j; 57 | 58 | i = 0; 59 | j = 0; 60 | while (str[i]) 61 | { 62 | if (str[i] != c) 63 | { 64 | tab[j] = malloc(sizeof(char) * (ft_slen(&str[i], c) + 1)); 65 | if (!tab) 66 | return (ft_free(tab, j)); 67 | while ((str[i]) && (str[i] != c)) 68 | tab[j][k++] = str[i++]; 69 | tab[j][k] = '\0'; 70 | j++; 71 | k = 0; 72 | } 73 | else 74 | i++; 75 | } 76 | tab[j] = NULL; 77 | return (tab); 78 | } 79 | 80 | char **ft_split(char const *s, char c) 81 | { 82 | int k; 83 | char **tab; 84 | char *str; 85 | 86 | k = 0; 87 | if (!s) 88 | return (NULL); 89 | str = (char *)s; 90 | tab = malloc(sizeof(char *) * (ft_strtab(str, c) + 1)); 91 | if (!tab) 92 | return (NULL); 93 | tab = ft_decoupe(tab, str, k, c); 94 | return (tab); 95 | } 96 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: motroian +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/11/10 17:13:25 by motroian #+# #+# # 9 | # Updated: 2022/11/21 18:03:45 by motroian ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | SRCS = ft_atoi.c \ 14 | ft_isalpha.c \ 15 | ft_isalnum.c \ 16 | ft_isascii.c \ 17 | ft_isdigit.c \ 18 | ft_isprint.c \ 19 | ft_memcpy.c \ 20 | ft_memchr.c \ 21 | ft_memset.c \ 22 | ft_memcmp.c \ 23 | ft_memmove.c \ 24 | ft_tolower.c \ 25 | ft_toupper.c \ 26 | ft_bzero.c \ 27 | ft_calloc.c \ 28 | ft_strlcpy.c \ 29 | ft_strlcat.c \ 30 | ft_strnstr.c \ 31 | ft_strdup.c \ 32 | ft_strlen.c \ 33 | ft_strchr.c \ 34 | ft_strrchr.c \ 35 | ft_strncmp.c \ 36 | ft_substr.c \ 37 | ft_strjoin.c \ 38 | ft_strtrim.c \ 39 | ft_split.c \ 40 | ft_itoa.c \ 41 | ft_strmapi.c \ 42 | ft_striteri.c \ 43 | ft_putchar_fd.c \ 44 | ft_putstr_fd.c \ 45 | ft_putendl_fd.c \ 46 | ft_putnbr_fd.c \ 47 | 48 | 49 | OBJS = ${SRCS:.c=.o} 50 | 51 | SRCSBONUS = ft_lstnew.c \ 52 | ft_lstadd_front.c \ 53 | ft_lstsize.c \ 54 | ft_lstlast.c \ 55 | ft_lstadd_back.c \ 56 | ft_lstdelone.c \ 57 | ft_lstclear.c \ 58 | ft_lstiter.c \ 59 | ft_lstmap.c \ 60 | 61 | OBJSBONUS = ${SRCSBONUS:.c=.o} 62 | 63 | 64 | NAME = libft.a 65 | CC = gcc 66 | CFLAGS = -Wall -Wextra -Werror -g 67 | RM = rm -f 68 | 69 | all: ${NAME} 70 | 71 | .c.o: 72 | ${CC} ${CFLAGS} -c $< -o ${<:.c=.o} 73 | 74 | $(NAME): $(OBJS) 75 | ar -rcs $(NAME) $(OBJS) 76 | 77 | bonus: ${OBJS} ${OBJSBONUS} 78 | ar -rcs ${NAME} ${OBJS} ${OBJSBONUS} 79 | 80 | clean: 81 | ${RM} ${OBJS} ${OBJSBONUS} 82 | 83 | fclean: clean 84 | ${RM} ${NAME} 85 | 86 | re: fclean all 87 | 88 | 89 | .PHONY: bonus all clean fclean re 90 | -------------------------------------------------------------------------------- /libft.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* libft.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: motroian +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/09 15:47:03 by motroian #+# #+# */ 9 | /* Updated: 2022/11/20 20:45:21 by motroian ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LIBFT_H 14 | # define LIBFT_H 15 | # include 16 | # include 17 | # include 18 | # include 19 | 20 | typedef struct s_list 21 | { 22 | void *content; 23 | struct s_list *next; 24 | } t_list; 25 | 26 | //is 27 | int ft_isalpha(int nb); 28 | int ft_isdigit(int nb); 29 | int ft_isalnum(int nb); 30 | int ft_isascii(int nb); 31 | int ft_isprint(int nb); 32 | 33 | //mem 34 | void *ft_memset(void *s, int c, size_t n); 35 | void ft_bzero(void *s, size_t n); 36 | void *ft_memcpy(void *dest, const void *src, size_t n); 37 | void *ft_memmove(void *dest, const void *src, size_t n); 38 | void *ft_memchr(const void *s, int c, size_t n); 39 | int ft_memcmp(const void *s1, const void *s2, size_t n); 40 | 41 | //str 42 | size_t ft_strlen(const char *s); 43 | char *ft_strchr(const char *s, int c); 44 | char *ft_strrchr(const char *s, int c); 45 | size_t ft_strlcpy(char *dst, const char *src, size_t size); 46 | size_t ft_strlcat(char *dst, const char *src, size_t size); 47 | int ft_strncmp(const char *s1, const char *s2, size_t n); 48 | char *ft_strnstr(const char *s1, const char *s2, size_t n); 49 | char *ft_strdup(const char *str); 50 | char *ft_strjoin(char const *s1, char const *s2); 51 | char *ft_strtrim(char const *s1, char const *set); 52 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); 53 | void ft_striteri(char *s, void (*f)(unsigned int, char*)); 54 | 55 | //rest 56 | int ft_toupper(int c); 57 | int ft_tolower(int c); 58 | int ft_atoi(const char *str); 59 | void *ft_calloc(size_t nmemb, size_t size); 60 | char *ft_substr(char const *s, unsigned int start, size_t len); 61 | char **ft_split(char const *s, char c); 62 | char *ft_itoa(int n); 63 | 64 | //FD 65 | void ft_putchar_fd(char c, int fd); 66 | void ft_putstr_fd(char *s, int fd); 67 | void ft_putendl_fd(char *s, int fd); 68 | void ft_putnbr_fd(int n, int fd); 69 | 70 | //list 71 | t_list *ft_lstnew(void *content); 72 | t_list *ft_lstlast(t_list *lst); 73 | t_list *ft_lstmap(t_list *lst, void *(*f)(void *), 74 | void (*del)(void *)); 75 | 76 | int ft_lstsize(t_list *lst); 77 | 78 | void ft_lstadd_front(t_list **lst, t_list *new); 79 | void ft_lstadd_back(t_list **lst, t_list *new); 80 | void ft_lstdelone(t_list *lst, void (*del)(void*)); 81 | void ft_lstclear(t_list **lst, void (*del)(void*)); 82 | void ft_lstiter(t_list *lst, void (*f)(void *)); 83 | 84 | #endif 85 | --------------------------------------------------------------------------------