├── .gitignore ├── Makefile ├── author ├── ft_atoi.c ├── ft_bzero.c ├── ft_calloc.c ├── ft_isalnum.c ├── ft_isalpha.c ├── ft_isascii.c ├── ft_isdigit.c ├── ft_isprint.c ├── ft_itoa.c ├── ft_lstadd_back_bonus.c ├── ft_lstadd_front_bonus.c ├── ft_lstclear_bonus.c ├── ft_lstdelone_bonus.c ├── ft_lstiter_bonus.c ├── ft_lstlast_bonus.c ├── ft_lstmap_bonus.c ├── ft_lstnew_bonus.c ├── ft_lstsize_bonus.c ├── ft_memccpy.c ├── ft_memchr.c ├── ft_memcmp.c ├── ft_memcpy.c ├── ft_memmove.c ├── ft_memset.c ├── ft_putchar_fd.c ├── ft_putendl_fd.c ├── ft_putnbr_fd.c ├── ft_putstr_fd.c ├── ft_split.c ├── ft_strchr.c ├── ft_strcmp.c ├── ft_strdup.c ├── ft_strjoin.c ├── ft_strlcat.c ├── ft_strlcpy.c ├── ft_strlen.c ├── ft_strmapi.c ├── ft_strncmp.c ├── ft_strnstr.c ├── ft_strrchr.c ├── ft_strtrim.c ├── ft_substr.c ├── ft_tolower.c ├── ft_toupper.c └── libft.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SRCS = ft_strcmp.c ft_memset.c ft_bzero.c ft_calloc.c ft_memcpy.c ft_memccpy.c ft_memmove.c ft_memchr.c ft_memcmp.c ft_strlen.c ft_strlcat.c ft_strlcpy.c ft_strchr.c ft_strrchr.c ft_strnstr.c ft_strncmp.c ft_atoi.c ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c ft_toupper.c ft_tolower.c ft_strdup.c ft_substr.c ft_strjoin.c ft_strtrim.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c ft_itoa.c ft_strmapi.c ft_split.c 2 | SRCS_B = ft_lstnew_bonus.c ft_lstadd_front_bonus.c ft_lstsize_bonus.c ft_lstlast_bonus.c ft_lstadd_back_bonus.c ft_lstdelone_bonus.c ft_lstclear_bonus.c ft_lstiter_bonus.c ft_lstmap_bonus.c 3 | OBJS = ${SRCS:.c=.o} 4 | OBJS_B = ${SRCS_B:.c=.o} 5 | NAME = libft.a 6 | CC = cc 7 | RM = rm -f 8 | CFLAGS = -Wall -Werror -Wextra 9 | .c.o: 10 | ${CC} ${FLAGS} -c $< -o ${<:.c=.o} 11 | ${NAME}: ${OBJS} 12 | ar rc ${NAME} ${OBJS} 13 | ranlib ${NAME} 14 | bonus: ${OBJS} ${OBJS_B} 15 | ar rc ${NAME} ${OBJS} ${OBJS_B} 16 | ranlib ${NAME} 17 | all: ${NAME} 18 | clean: 19 | ${RM} ${OBJS} ${OBJS_B} 20 | fclean: clean 21 | ${RM} ${NAME} 22 | re: fclean bonus 23 | .PHONY: bonus all clean fclean re 24 | -------------------------------------------------------------------------------- /author: -------------------------------------------------------------------------------- 1 | abello-r 2 | -------------------------------------------------------------------------------- /ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/07 18:56:35 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/25 14:50:11 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_atoi(const char *str) 16 | { 17 | long i; 18 | long sign; 19 | long nb; 20 | 21 | nb = 0; 22 | sign = 1; 23 | i = 0; 24 | while ((str[i] == '\n' || str[i] == '\t' || str[i] == ' ' ) 25 | || str[i] == '\v' || str[i] == '\f' || str[i] == '\r') 26 | i++; 27 | if (str[i] == '-') 28 | sign = -1; 29 | if (str[i] == '-' || str[i] == '+') 30 | i++; 31 | while (str[i] >= '0' && str[i] <= '9') 32 | { 33 | nb = nb * 10 + (str[i] - '0'); 34 | i++; 35 | } 36 | return (nb * sign); 37 | } 38 | -------------------------------------------------------------------------------- /ft_bzero.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_bzero.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/08 13:51:50 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/24 12:25:29 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_bzero(void *s, size_t n) 16 | { 17 | ft_memset(s, 0, n); 18 | } 19 | -------------------------------------------------------------------------------- /ft_calloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_calloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/11 12:35:55 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/25 14:51:56 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_calloc(size_t count, size_t size) 16 | { 17 | void *ptr; 18 | 19 | ptr = malloc(count * size); 20 | if (!(ptr)) 21 | return (NULL); 22 | ft_bzero(ptr, count * size); 23 | return (ptr); 24 | } 25 | -------------------------------------------------------------------------------- /ft_isalnum.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalnum.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/07 16:36:30 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/25 14:53:17 by abello-r ### ########.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_isalpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/07 16:37:18 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/25 14:55:11 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isalpha(int c) 16 | { 17 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) 18 | { 19 | return (1); 20 | } 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /ft_isascii.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isascii.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/07 17:06:37 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/14 18:47:37 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isascii(int c) 16 | { 17 | if (c >= 0 && c <= 127) 18 | { 19 | return (1); 20 | } 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /ft_isdigit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isdigit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/07 16:38:06 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/25 15:12:40 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isdigit(int c) 16 | { 17 | if (c >= '0' && c <= '9') 18 | { 19 | return (1); 20 | } 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /ft_isprint.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isprint.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/07 16:45:26 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/25 15:13:58 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isprint(int c) 16 | { 17 | if (c >= ' ' && c <= '~') 18 | { 19 | return (1); 20 | } 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /ft_itoa.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_itoa.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/16 13:12:01 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/17 16:49:56 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | static char *ft_array(char *x, unsigned int number, long int len) 16 | { 17 | while (number > 0) 18 | { 19 | x[len--] = 48 + (number % 10); 20 | number = number / 10; 21 | } 22 | return (x); 23 | } 24 | 25 | static long int ft_len(int n) 26 | { 27 | int len; 28 | 29 | len = 0; 30 | if (n <= 0) 31 | len = 1; 32 | while (n != 0) 33 | { 34 | len++; 35 | n = n / 10; 36 | } 37 | return (len); 38 | } 39 | 40 | char *ft_itoa(int n) 41 | { 42 | char *x; 43 | long int len; 44 | unsigned int number; 45 | int sign; 46 | 47 | sign = 1; 48 | len = ft_len(n); 49 | x = (char *)malloc(sizeof(char) * (len + 1)); 50 | if (!(x)) 51 | return (NULL); 52 | x[len--] = '\0'; 53 | if (n == 0) 54 | x[0] = '0'; 55 | if (n < 0) 56 | { 57 | sign *= -1; 58 | number = n * -1; 59 | x[0] = '-'; 60 | } 61 | else 62 | number = n; 63 | x = ft_array(x, number, len); 64 | return (x); 65 | } 66 | -------------------------------------------------------------------------------- /ft_lstadd_back_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_back_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/20 14:52:46 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/21 21:27:42 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_back(t_list **lst, t_list *new) 16 | { 17 | t_list *i; 18 | 19 | if (!*lst) 20 | { 21 | *lst = new; 22 | return ; 23 | } 24 | i = *lst; 25 | while (i->next) 26 | { 27 | i = i->next; 28 | } 29 | i->next = new; 30 | } 31 | -------------------------------------------------------------------------------- /ft_lstadd_front_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_front_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/20 12:58:59 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/20 18:52:52 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_front(t_list **alst, t_list *new) 16 | { 17 | if (!new) 18 | return ; 19 | if (!alst) 20 | return ; 21 | new->next = *alst; 22 | *alst = new; 23 | } 24 | -------------------------------------------------------------------------------- /ft_lstclear_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstclear_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/20 19:42:35 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/21 21:58:30 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstclear(t_list **lst, void (*del)(void *)) 16 | { 17 | t_list *x; 18 | 19 | if (!lst) 20 | return ; 21 | while (*lst) 22 | { 23 | x = (*lst)->next; 24 | del((*lst)->content); 25 | free(*lst); 26 | (*lst) = x; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ft_lstdelone_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstdelone_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/20 17:56:32 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/21 19:06:30 by abello-r ### ########.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 | return ; 21 | del(lst->content); 22 | free(lst); 23 | } 24 | -------------------------------------------------------------------------------- /ft_lstiter_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstiter_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/20 20:29:35 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/21 21:57:53 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstiter(t_list *lst, void (*f)(void *)) 16 | { 17 | if (!lst) 18 | return ; 19 | while (lst) 20 | { 21 | f((lst)->content); 22 | lst = lst->next; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ft_lstlast_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstlast_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/20 14:33:33 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/20 16:30:33 by abello-r ### ########.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_lstmap_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstmap_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/20 20:47:55 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/21 19:05:22 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstmap(t_list *l, void *(*f)(void *), void (*del)(void *)) 16 | { 17 | t_list *x; 18 | t_list *new; 19 | 20 | if (!l) 21 | return (NULL); 22 | new = ft_lstnew(f(l->content)); 23 | if (!(new)) 24 | return (NULL); 25 | x = new; 26 | while (l) 27 | { 28 | if (l->next) 29 | { 30 | new->next = ft_lstnew(f(l->next->content)); 31 | if (!(new->next)) 32 | { 33 | ft_lstclear(&new, del); 34 | return (NULL); 35 | } 36 | new = new->next; 37 | } 38 | l = l->next; 39 | } 40 | new->next = NULL; 41 | return (x); 42 | } 43 | -------------------------------------------------------------------------------- /ft_lstnew_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstnew_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/20 12:06:17 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/20 13:01:10 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstnew(void *content) 16 | { 17 | t_list *x; 18 | 19 | x = malloc(sizeof(t_list)); 20 | if (!(x)) 21 | return (NULL); 22 | x->content = content; 23 | x->next = NULL; 24 | return (x); 25 | } 26 | -------------------------------------------------------------------------------- /ft_lstsize_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstsize_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/20 14:07:03 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/20 14:33:12 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_lstsize(t_list *lst) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (lst) 21 | { 22 | lst = lst->next; 23 | i++; 24 | } 25 | return (i); 26 | } 27 | -------------------------------------------------------------------------------- /ft_memccpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memccpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/09 15:47:10 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/25 15:18:03 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memccpy(void *dst, const void *src, int c, size_t n) 16 | { 17 | while (n--) 18 | { 19 | *(unsigned char *)dst++ = *(unsigned char *)src; 20 | if (*(unsigned char *)src++ == (unsigned char)c) 21 | return (dst); 22 | } 23 | return (NULL); 24 | } 25 | -------------------------------------------------------------------------------- /ft_memchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/08 21:43:15 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/25 15:18:44 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memchr(const void *s, int c, size_t n) 16 | { 17 | size_t count; 18 | 19 | count = 0; 20 | while (n--) 21 | { 22 | if (*(unsigned char *)s == (unsigned char)c) 23 | return ((unsigned char *)s); 24 | s++; 25 | } 26 | return (NULL); 27 | } 28 | -------------------------------------------------------------------------------- /ft_memcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/08 21:25:34 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/25 15:23:43 by abello-r ### ########.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 int i; 18 | 19 | i = 0; 20 | while (i < n) 21 | { 22 | if (((unsigned char *)s1)[i] != ((unsigned char *)s2)[i]) 23 | return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]); 24 | i++; 25 | } 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /ft_memcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/08 18:26:27 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/24 12:30:02 by abello-r ### ########.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 (n == 0 || dst == src) 20 | return (dst); 21 | i = 0; 22 | while (i < n) 23 | { 24 | ((char *)dst)[i] = ((char *)src)[i]; 25 | i++; 26 | } 27 | return (dst); 28 | } 29 | -------------------------------------------------------------------------------- /ft_memmove.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memmove.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/09 11:28:04 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/25 15:26:06 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memmove(void *dst, const void *src, size_t len) 16 | { 17 | unsigned char *x; 18 | const unsigned char *y; 19 | 20 | x = ((unsigned char *)dst); 21 | y = ((const unsigned char *)src); 22 | if (x == y) 23 | return (dst); 24 | else if (x > y) 25 | { 26 | y = y + len - 1; 27 | x = x + len - 1; 28 | while (len > 0) 29 | { 30 | *x = *y; 31 | x--; 32 | y--; 33 | len--; 34 | } 35 | } 36 | else 37 | dst = ft_memcpy(x, y, len); 38 | return (dst); 39 | } 40 | -------------------------------------------------------------------------------- /ft_memset.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memset.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/08 13:00:48 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/24 12:24:28 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memset(void *b, int c, size_t len) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (i < len) 21 | { 22 | ((char *)b)[i] = (unsigned char)c; 23 | i++; 24 | } 25 | return (b); 26 | } 27 | -------------------------------------------------------------------------------- /ft_putchar_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/12 23:24:38 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/12 23:33:56 by abello-r ### ########.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_putendl_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putendl_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/13 12:40:39 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/15 15:54:42 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putendl_fd(char *s, int fd) 16 | { 17 | size_t i; 18 | char x; 19 | 20 | if (!s) 21 | return ; 22 | i = 0; 23 | while (i != ft_strlen(s)) 24 | { 25 | x = s[i]; 26 | write(fd, &x, 1); 27 | i++; 28 | } 29 | write(fd, "\n", 1); 30 | } 31 | -------------------------------------------------------------------------------- /ft_putnbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/13 12:49:42 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/13 14:41:14 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | static void ft_putchar(char x, int fd) 16 | { 17 | write(fd, &x, 1); 18 | } 19 | 20 | void ft_putnbr_fd(int n, int fd) 21 | { 22 | int long i; 23 | 24 | i = n; 25 | if (i < 0) 26 | { 27 | write(fd, "-", 1); 28 | i = i * -1; 29 | } 30 | if (i > 9) 31 | ft_putnbr_fd(i / 10, fd); 32 | ft_putchar(i % 10 + 48, fd); 33 | } 34 | -------------------------------------------------------------------------------- /ft_putstr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/13 12:14:38 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/15 15:48:56 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putstr_fd(char *s, int fd) 16 | { 17 | size_t i; 18 | char c; 19 | 20 | if (!s) 21 | return ; 22 | i = 0; 23 | while (i != ft_strlen(s)) 24 | { 25 | c = s[i]; 26 | write(fd, &c, 1); 27 | i++; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ft_split.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_split.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/20 13:07:27 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/20 13:07:48 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int count_strings(char const *s, char c) 16 | { 17 | int act_pos; 18 | int str_count; 19 | 20 | act_pos = 0; 21 | str_count = 0; 22 | if (s[act_pos] == c) 23 | str_count--; 24 | while (s[act_pos] != '\0') 25 | { 26 | if (s[act_pos] == c && s[act_pos + 1] != c && s[act_pos + 1] != '\0') 27 | str_count++; 28 | act_pos++; 29 | } 30 | str_count++; 31 | return (str_count); 32 | } 33 | 34 | char *malloc_strings(const char *s, char c) 35 | { 36 | char *word; 37 | int i; 38 | 39 | i = 0; 40 | while (s[i] && s[i] != c) 41 | i++; 42 | word = (char *)malloc(sizeof(char) * (i + 1)); 43 | if (!word) 44 | return (NULL); 45 | i = 0; 46 | while (s[i] && s[i] != c) 47 | { 48 | word[i] = s[i]; 49 | i++; 50 | } 51 | word[i] = '\0'; 52 | return (word); 53 | } 54 | 55 | char **ft_split(char const *s, char c) 56 | { 57 | int words; 58 | char **tab; 59 | int i; 60 | 61 | if (!s) 62 | return (NULL); 63 | words = count_strings(s, c); 64 | tab = (char **)malloc(sizeof(char *) * (words + 1)); 65 | if (!tab) 66 | return (NULL); 67 | i = 0; 68 | while (*s) 69 | { 70 | while (*s && *s == c) 71 | s++; 72 | if (*s && *s != c) 73 | { 74 | tab[i] = malloc_strings(s, c); 75 | i++; 76 | while (*s && *s != c) 77 | s++; 78 | } 79 | } 80 | tab[i] = NULL; 81 | return (tab); 82 | } 83 | -------------------------------------------------------------------------------- /ft_strchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/10 10:43:43 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/25 15:29:14 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strchr(const char *s, int c) 16 | { 17 | while (*s) 18 | { 19 | if (*s == (char)c) 20 | return ((char *)s); 21 | s++; 22 | } 23 | if ((char)c == '\0') 24 | return ((char *)s); 25 | return (NULL); 26 | } 27 | -------------------------------------------------------------------------------- /ft_strcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/04/30 15:44:46 by abello-r #+# #+# */ 9 | /* Updated: 2021/04/30 15:51:15 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_strcmp(char *s1, char *s2) 16 | { 17 | int i; 18 | 19 | i = -1; 20 | if (ft_strlen(s1) != ft_strlen(s2)) 21 | return (1); 22 | while (s1[++i] != '\0') 23 | if (s1[i] != s2[i]) 24 | return (1); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/11 14:43:06 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/25 15:31:05 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strdup(const char *s1) 16 | { 17 | char *s2; 18 | size_t i; 19 | 20 | i = ft_strlen(s1); 21 | s2 = malloc(i + 1); 22 | if (!(s2)) 23 | return (NULL); 24 | ft_memcpy(s2, s1, i); 25 | s2[i] = '\0'; 26 | return (s2); 27 | } 28 | -------------------------------------------------------------------------------- /ft_strjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/12 13:32:01 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/14 19:32:41 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strjoin(char const *s1, char const *s2) 16 | { 17 | char *x; 18 | size_t c1; 19 | size_t c2; 20 | size_t i; 21 | 22 | i = 0; 23 | c2 = 0; 24 | c1 = 0; 25 | if (s1 == NULL || s2 == NULL) 26 | return (NULL); 27 | x = (char *)malloc(sizeof(char) * ft_strlen(s1) + ft_strlen(s2) + 1); 28 | if (!(x)) 29 | return (NULL); 30 | while (c1 != ft_strlen(s1)) 31 | { 32 | x[i] = s1[c1]; 33 | ++i && ++c1; 34 | } 35 | while (c2 != ft_strlen(s2)) 36 | { 37 | x[i] = s2[c2]; 38 | ++i && ++c2; 39 | } 40 | x[i] = '\0'; 41 | return (x); 42 | } 43 | -------------------------------------------------------------------------------- /ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/10 17:31:27 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/26 12:11:57 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlcat(char *dst, const char *src, size_t dstsize) 16 | { 17 | size_t len; 18 | size_t i; 19 | 20 | len = 0; 21 | i = 0; 22 | while (dst[i] && i < dstsize) 23 | i++; 24 | len = i; 25 | while (src[i - len] && i + 1 < dstsize) 26 | { 27 | dst[i] = src[i - len]; 28 | i++; 29 | } 30 | if (len < dstsize) 31 | dst[i] = '\0'; 32 | return (len + ft_strlen(src)); 33 | } 34 | -------------------------------------------------------------------------------- /ft_strlcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/10 18:35:49 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/24 15:18:59 by abello-r ### ########.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 len; 18 | size_t c1; 19 | size_t c2; 20 | 21 | c1 = 0; 22 | if (!src) 23 | return (0); 24 | len = ft_strlen(src); 25 | if (dstsize == 0) 26 | return (len); 27 | c2 = dstsize - 1; 28 | while (c2 > 0 && src[c1] != '\0') 29 | { 30 | dst[c1] = src[c1]; 31 | c1++; 32 | c2--; 33 | } 34 | dst[c1] = '\0'; 35 | return (len); 36 | } 37 | -------------------------------------------------------------------------------- /ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/08 19:57:34 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/23 12:38:30 by abello-r ### ########.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] != '\0') 21 | { 22 | i++; 23 | } 24 | return (i); 25 | } 26 | -------------------------------------------------------------------------------- /ft_strmapi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmapi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/17 13:03:50 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/17 13:34:22 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strmapi(char const *s, char (*f) (unsigned int, char)) 16 | { 17 | char *x; 18 | unsigned int i; 19 | 20 | i = 0; 21 | if (!s) 22 | return (NULL); 23 | x = malloc(sizeof(char) * ft_strlen(s) + 1); 24 | if (!(x)) 25 | return (NULL); 26 | while (i != ft_strlen(s)) 27 | { 28 | x[i] = (*f)(i, s[i]); 29 | i++; 30 | } 31 | x[i] = '\0'; 32 | return (x); 33 | } 34 | -------------------------------------------------------------------------------- /ft_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/07 19:39:58 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/24 14:59:31 by abello-r ### ########.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 *ss1; 18 | unsigned char *ss2; 19 | size_t c1; 20 | size_t c2; 21 | 22 | ss1 = (unsigned char *)s1; 23 | ss2 = (unsigned char *)s2; 24 | c1 = 0; 25 | c2 = 0; 26 | if (n == 0) 27 | return (c2); 28 | while ((ss1[c1] == ss2[c1] && ss1[c1] != '\0') && c1 < n) 29 | c1++; 30 | if (c1 == n) 31 | c1--; 32 | c2 = ss1[c1] - ss2[c1]; 33 | return (c2); 34 | } 35 | -------------------------------------------------------------------------------- /ft_strnstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/10 15:05:09 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/26 12:11:28 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strnstr(const char *h, const char *needle, size_t len) 16 | { 17 | size_t c; 18 | 19 | if (*needle == 0 || h == needle) 20 | return ((char *)h); 21 | c = ft_strlen(needle); 22 | while (*h && c <= len--) 23 | { 24 | if (!(ft_strncmp((char *)h, (char *)needle, c))) 25 | return ((char *)h); 26 | h++; 27 | } 28 | return (NULL); 29 | } 30 | -------------------------------------------------------------------------------- /ft_strrchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strrchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/10 11:47:25 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/10 13:47:14 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strrchr(const char *s, int c) 16 | { 17 | size_t i; 18 | char x; 19 | 20 | i = 0; 21 | x = ((char)c); 22 | while (s[i] != '\0') 23 | { 24 | i++; 25 | } 26 | while (i > 0) 27 | { 28 | if (s[i] == x) 29 | { 30 | return (&((char *)s)[i]); 31 | } 32 | i--; 33 | } 34 | if (i == 0) 35 | { 36 | if (s[i] == x) 37 | return (&((char *)s)[i]); 38 | } 39 | return (0); 40 | } 41 | -------------------------------------------------------------------------------- /ft_strtrim.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strtrim.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/14 10:49:49 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/14 18:53:27 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strtrim(char const *s1, char const *set) 16 | { 17 | size_t len; 18 | char *x; 19 | 20 | if (!s1 || !set) 21 | return (NULL); 22 | while (ft_strchr(set, *s1) && *s1 != '\0') 23 | { 24 | s1++; 25 | } 26 | if (*s1 == '\0') 27 | return (ft_strdup("")); 28 | len = ft_strlen(s1); 29 | while (ft_strchr(set, s1[len])) 30 | { 31 | len--; 32 | } 33 | x = ft_substr(s1, 0, len + 1); 34 | return (x); 35 | } 36 | -------------------------------------------------------------------------------- /ft_substr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_substr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/11 18:07:56 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/22 12:24:37 by abello-r ### ########.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 *x; 18 | size_t i; 19 | 20 | i = 0; 21 | if (!s) 22 | return (NULL); 23 | if (*s == '\0') 24 | return (ft_strdup("")); 25 | if (start > ft_strlen(s)) 26 | return (ft_strdup("")); 27 | x = (char *)malloc(sizeof(char) * len + 1); 28 | if (!(x)) 29 | return (NULL); 30 | while (i < len) 31 | { 32 | x[i] = s[start + i]; 33 | i++; 34 | } 35 | x[i] = '\0'; 36 | return (x); 37 | } 38 | -------------------------------------------------------------------------------- /ft_tolower.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_tolower.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/07 18:51:48 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/25 15:46:09 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_tolower(int c) 16 | { 17 | if (c >= 'A' && c <= 'Z') 18 | return (c + 32); 19 | return (c); 20 | } 21 | -------------------------------------------------------------------------------- /ft_toupper.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_toupper.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/07 18:36:33 by abello-r #+# #+# */ 9 | /* Updated: 2020/01/25 15:47:01 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_toupper(int c) 16 | { 17 | if (c >= 'a' && c <= 'z') 18 | return (c - 32); 19 | return (c); 20 | } 21 | -------------------------------------------------------------------------------- /libft.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* libft.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/01/08 14:51:42 by abello-r #+# #+# */ 9 | /* Updated: 2021/04/30 15:48:58 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LIBFT_H 14 | # define LIBFT_H 15 | 16 | # include 17 | # include 18 | # include 19 | # include 20 | # include 21 | 22 | typedef struct s_list 23 | { 24 | void *content; 25 | struct s_list *next; 26 | } t_list; 27 | void *ft_memset(void *b, int c, size_t len); 28 | void ft_bzero(void *s, size_t n); 29 | int ft_tolower(int c); 30 | int ft_toupper(int c); 31 | int ft_isprint(int c); 32 | int ft_isascii(int c); 33 | int ft_isalnum(int c); 34 | int ft_isdigit(int c); 35 | int ft_isalpha(int c); 36 | int ft_atoi(const char *str); 37 | int ft_strncmp(const char *s1, const char *s2, size_t n); 38 | void *ft_memcpy(void *dst, const void *src, size_t n); 39 | size_t ft_strlen(const char *s); 40 | int ft_memcmp(const void *s1, const void *s2, size_t n); 41 | void *ft_memchr(const void *s, int c, size_t n); 42 | void *ft_memmove(void *dst, const void *src, size_t len); 43 | void *ft_memccpy(void *dst, const void *src, int c, size_t n); 44 | char *ft_strchr(const char *s, int c); 45 | char *ft_strrchr(const char *s, int c); 46 | char *ft_strnstr(const char *h, const char *needle, size_t len); 47 | size_t ft_strlcat(char *dst, const char *src, size_t dstsize); 48 | size_t ft_strlcpy(char *dst, const char *src, size_t dstsize); 49 | void *ft_calloc(size_t count, size_t size); 50 | char *ft_strdup(const char *s1); 51 | char *ft_substr(char const *s, unsigned int start, size_t len); 52 | char *ft_strjoin(char const *s1, char const *s2); 53 | char *ft_strtrim(char const *s1, char const *set); 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 | char *ft_itoa(int n); 59 | char *ft_strmapi(char const *s, char (*f) (unsigned int, char)); 60 | char **ft_split(char const *s, char c); 61 | t_list *ft_lstnew(void *content); 62 | void ft_lstadd_front(t_list **alst, t_list *new); 63 | int ft_lstsize(t_list *lst); 64 | t_list *ft_lstlast(t_list *lst); 65 | void ft_lstadd_back(t_list **lst, t_list *new); 66 | void ft_lstdelone(t_list *lst, void (*del)(void *)); 67 | void ft_lstclear(t_list **lst, void (*del)(void *)); 68 | void ft_lstiter(t_list *lst, void (*f)(void *)); 69 | t_list *ft_lstmap(t_list *l, void *(*f)(void *), void (*del)(void *)); 70 | int ft_strcmp(char *s1, char *s2); 71 | #endif 72 | --------------------------------------------------------------------------------