├── .gitignore ├── Makefile ├── flag1.c ├── flag2.c ├── flag3.c ├── flag4.c ├── flag5.c ├── flag6.c ├── flag7.c ├── ft_printf.c ├── ft_setformat.c ├── libft ├── Makefile ├── ft_atoi.c ├── ft_hexa.c ├── ft_hexamayus.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_memorypointer.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_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 ├── ft_unsigned_fd.c └── libft.h └── libftprintf.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 = flag1.c flag2.c flag3.c flag4.c flag5.c flag6.c flag7.c ft_setformat.c ft_printf.c 2 | 3 | OBJS = ${SRCS:.c=.o} 4 | 5 | NAME = libftprintf.a 6 | CC = cc 7 | RM = rm -f 8 | CFLAGS = -Wall -Werror -Wextra 9 | 10 | .c.o: 11 | ${CC} ${FLAGS} -c $< -o ${<:.c=.o} 12 | 13 | $(NAME): ${OBJS} 14 | make -sC ./libft/ 15 | cp libft/libft.a . 16 | mv libft.a $(NAME) 17 | ar rc $(NAME) $(OBJS) 18 | ranlib $(NAME) 19 | 20 | all: $(NAME) 21 | 22 | clean: 23 | $(RM) $(OBJS) 24 | make -sC ./libft/ clean 25 | 26 | fclean: clean 27 | $(RM) $(NAME) 28 | make -sC ./libft/ fclean 29 | 30 | re: fclean all 31 | 32 | .PHONY: all fclean re 33 | -------------------------------------------------------------------------------- /flag1.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* flag1.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/02/21 02:00:41 by abello-r #+# #+# */ 9 | /* Updated: 2020/02/21 02:00:48 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libftprintf.h" 14 | 15 | size_t ft_intlen(long nb) 16 | { 17 | size_t count; 18 | 19 | count = 0; 20 | if (nb == 0) 21 | { 22 | count++; 23 | return (count); 24 | } 25 | if (nb < 0) 26 | { 27 | nb *= -1; 28 | count++; 29 | } 30 | while (nb > 0) 31 | { 32 | nb = nb / 10; 33 | count++; 34 | } 35 | return (count); 36 | } 37 | 38 | void ft_while(int space, int zero, t_printf *format, int nb) 39 | { 40 | int flag; 41 | 42 | flag = (nb < 0 && (space > format->precision && format->zero_space == '0')) 43 | ? write(1, "-", 1) : 0; 44 | while (space > 0 && format->tab != '-') 45 | { 46 | format->len_str += write(1, (format->zero_space != '0' || 47 | (format->dot == '.' && format->precision >= 0)) ? " " : "0", 1); 48 | space--; 49 | } 50 | (nb < 0 && flag == 0) ? ft_putchar_fd('-', 1) : 0; 51 | while (zero-- > 0) 52 | format->len_str += write(1, "0", 1); 53 | (format->dot == '.' && nb == 0 && format->precision == 0) 54 | ? 0 : ft_putnbr_fd(nb, 1); 55 | while (space-- > 0) 56 | format->len_str += write(1, " ", 1); 57 | format->len_str -= (format->dot == '.' && nb == 0 && 58 | format->precision == 0) ? 1 : 0; 59 | } 60 | 61 | void ft_spacex(t_printf *format, int nb) 62 | { 63 | int len; 64 | int space; 65 | int zero; 66 | 67 | format->len_str += len = ft_intlen(nb); 68 | space = format->width - ((format->precision < len) 69 | ? len : format->precision); 70 | space -= (nb < 0 && format->precision >= len) ? 1 : 0; 71 | space += (format->dot == '.' && nb == 0 && format->precision == 0) ? 1 : 0; 72 | zero = (nb < 0) ? (format->precision - len) + 1 : (format->precision - len); 73 | ft_while(space, zero, format, nb); 74 | } 75 | -------------------------------------------------------------------------------- /flag2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* flag2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/03/02 20:08:08 by abello-r #+# #+# */ 9 | /* Updated: 2020/03/02 20:08:12 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libftprintf.h" 14 | 15 | void ft_display_c(t_printf *format, int nb) 16 | { 17 | int space; 18 | int zero; 19 | 20 | zero = (format->zero_space == '0' && format->width > 0) ? 21 | format->width - 1 : 0; 22 | space = (format->width > 0) ? (format->width) : 0; 23 | space -= (format->width > 0 && format->tab != '-') ? 1 : 0; 24 | while (zero-- > 0 && format->tab != '-') 25 | { 26 | format->len_str += write(1, "0", 1); 27 | space = 0; 28 | } 29 | while (space-- > 0 && format->tab != '-') 30 | format->len_str += write(1, " ", 1); 31 | format->len_str += write(1, &nb, 1); 32 | while (space-- > 0 && format->tab == '-') 33 | format->len_str += write(1, " ", 1); 34 | } 35 | -------------------------------------------------------------------------------- /flag3.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* flag3.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/03/03 17:16:04 by abello-r #+# #+# */ 9 | /* Updated: 2020/03/03 17:16:07 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libftprintf.h" 14 | 15 | void ft_decision(t_printf *format, char *str, int len) 16 | { 17 | format->len_str += write(1, str, (format->dot == '.' && 18 | format->precision == -1) ? 0 : len); 19 | } 20 | 21 | void ft_display_s(t_printf *format, char *str) 22 | { 23 | int space; 24 | int len; 25 | int len_null; 26 | 27 | str = (str == NULL) ? "(null)" : str; 28 | len = ft_strlen(str); 29 | len -= (format->precision > 0 && 30 | format->precision < len) ? (len - format->precision) : 0; 31 | len -= (format->dot == '.' && format->tab == '-' && 32 | format->precision == 0 && format->width == 0) ? len : 0; 33 | len -= (format->dot == '.' && format->tab != '-' && 34 | format->precision == 0 && format->width == 0) ? len : 0; 35 | len -= (format->precision == 0 && format->width > 0 && 36 | format->zero_space == ' ' && format->dot == '.') ? len : 0; 37 | space = (format->width > 0) ? (format->width - len) : 0; 38 | space += (format->tab == '-') ? 1 : 0; 39 | format->zero_space = (format->tab == '-' && 40 | format->zero_space == '0') ? ' ' : format->zero_space; 41 | while (space-- > 0 && format->tab != '-') 42 | format->len_str += write(1, &format->zero_space, 1); 43 | (str == NULL) ? 0 : ft_decision(format, str, len); 44 | while (space-- > 0 && format->tab == '-') 45 | format->len_str += write(1, &format->zero_space, 1); 46 | } 47 | -------------------------------------------------------------------------------- /flag4.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* flag4.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/03/04 19:25:59 by abello-r #+# #+# */ 9 | /* Updated: 2020/03/04 19:26:00 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libftprintf.h" 14 | 15 | void ft_espacios(int space, int zero, t_printf *format, unsigned int nb) 16 | { 17 | int flag; 18 | 19 | flag = (nb < 0 && (space > format->precision && format->zero_space == '0')) 20 | ? write(1, "-", 1) : 0; 21 | while (space > 0 && format->tab != '-') 22 | { 23 | format->len_str += write(1, (format->zero_space != '0' || 24 | (format->dot == '.' && format->precision >= 0)) ? " " : "0", 1); 25 | space--; 26 | } 27 | while (zero-- > 0) 28 | format->len_str += write(1, "0", 1); 29 | (format->dot == '.' && nb == 0 && format->precision == 0) 30 | ? 0 : ft_putnbr_fd(nb, 1); 31 | while (space-- > 0) 32 | format->len_str += write(1, " ", 1); 33 | format->len_str -= (format->dot == '.' && nb == 0 && 34 | format->precision == 0) ? 1 : 0; 35 | } 36 | 37 | void ft_display_u(t_printf *format, unsigned int nb) 38 | { 39 | int len; 40 | int space; 41 | int zero; 42 | 43 | len = ft_intlen(nb); 44 | format->len_str += len = ft_intlen(nb); 45 | space = format->width - ((format->precision < len) 46 | ? len : format->precision); 47 | space -= (nb < 0 && format->precision >= len) ? 1 : 0; 48 | space += (format->dot == '.' && nb == 0 49 | && format->precision == 0) ? 1 : 0; 50 | zero = (nb < 0) ? (format->precision - len) + 1 : (format->precision - len); 51 | ft_espacios(space, zero, format, nb); 52 | } 53 | -------------------------------------------------------------------------------- /flag5.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* flag5.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/03/04 21:56:56 by abello-r #+# #+# */ 9 | /* Updated: 2020/03/04 21:56:59 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libftprintf.h" 14 | 15 | size_t ft_lenhexa(size_t nb) 16 | { 17 | size_t count; 18 | 19 | count = 0; 20 | if (nb == 0) 21 | { 22 | count++; 23 | return (count); 24 | } 25 | if (nb < 0) 26 | { 27 | nb *= -1; 28 | count++; 29 | } 30 | while (nb > 0) 31 | { 32 | nb = nb / 16; 33 | count++; 34 | } 35 | return (count); 36 | } 37 | 38 | void ft_aux(int space, int zero, t_printf *format, unsigned int nb) 39 | { 40 | int flag; 41 | 42 | while (space > 0 && format->tab != '-') 43 | { 44 | format->len_str += write(1, (format->zero_space != '0' || 45 | (format->dot == '.' && format->precision >= 0)) ? " " : "0", 1); 46 | space--; 47 | } 48 | while (zero-- > 0) 49 | format->len_str += write(1, "0", 1); 50 | (format->dot == '.' && nb == 0 && format->precision == 0) 51 | ? 0 : ft_hexa(nb); 52 | while (space-- > 0) 53 | format->len_str += write(1, " ", 1); 54 | format->len_str -= (format->dot == '.' && nb == 0 && 55 | format->precision == 0) ? 1 : 0; 56 | } 57 | 58 | void ft_display_x(t_printf *format, unsigned int nb) 59 | { 60 | int len; 61 | int space; 62 | int zero; 63 | 64 | format->len_str += len = ft_lenhexa(nb); 65 | space = format->width - ((format->precision < len) 66 | ? len : format->precision); 67 | space += (format->dot == '.' && nb == 0 && format->precision == 0) ? 1 : 0; 68 | zero = format->precision - len; 69 | ft_aux(space, zero, format, nb); 70 | } 71 | -------------------------------------------------------------------------------- /flag6.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* flag6.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/03/05 16:14:42 by abello-r #+# #+# */ 9 | /* Updated: 2020/03/05 16:14:44 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libftprintf.h" 14 | 15 | size_t ft_lenhexamayus(long nb) 16 | { 17 | size_t count; 18 | 19 | count = 0; 20 | if (nb == 0) 21 | { 22 | count++; 23 | return (count); 24 | } 25 | if (nb < 0) 26 | { 27 | nb *= -1; 28 | count++; 29 | } 30 | while (nb > 0) 31 | { 32 | nb = nb / 16; 33 | count++; 34 | } 35 | return (count); 36 | } 37 | 38 | void ft_auxiliar(int space, int zero, t_printf *format, int nb) 39 | { 40 | int flag; 41 | 42 | while (space > 0 && format->tab != '-') 43 | { 44 | format->len_str += write(1, (format->zero_space != '0' || 45 | (format->dot == '.' && format->precision >= 0)) ? " " : "0", 1); 46 | space--; 47 | } 48 | while (zero-- > 0) 49 | format->len_str += write(1, "0", 1); 50 | (format->dot == '.' && nb == 0 && format->precision == 0) 51 | ? 0 : ft_hexamayus(nb); 52 | while (space-- > 0) 53 | format->len_str += write(1, " ", 1); 54 | format->len_str -= (format->dot == '.' && nb == 0 && 55 | format->precision == 0) ? 1 : 0; 56 | } 57 | 58 | void ft_display_xmayus(t_printf *format, unsigned int nb) 59 | { 60 | int len; 61 | int space; 62 | int zero; 63 | 64 | format->len_str += len = ft_lenhexamayus(nb); 65 | space = format->width - ((format->precision < len) 66 | ? len : format->precision); 67 | space += (format->dot == '.' && nb == 0 && format->precision == 0) ? 1 : 0; 68 | zero = format->precision - len; 69 | ft_auxiliar(space, zero, format, nb); 70 | } 71 | -------------------------------------------------------------------------------- /flag7.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* flag7.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/03/05 17:00:30 by abello-r #+# #+# */ 9 | /* Updated: 2020/03/05 17:00:32 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libftprintf.h" 14 | 15 | size_t ft_lenhex_p(unsigned long nb) 16 | { 17 | size_t count; 18 | 19 | count = 0; 20 | if (nb == 0) 21 | { 22 | count++; 23 | return (count); 24 | } 25 | if (nb < 0) 26 | { 27 | nb *= -1; 28 | count++; 29 | } 30 | while (nb > 0) 31 | { 32 | nb = nb / 16; 33 | count++; 34 | } 35 | return (count); 36 | } 37 | 38 | void ft_help(int space, t_printf *format, int nb, char *ch) 39 | { 40 | int flag; 41 | 42 | while (space > 0 && format->tab != '-') 43 | { 44 | format->len_str += write(1, (format->zero_space != '0' || 45 | (format->dot == '.' && format->precision >= 0)) ? " " : "0", 1); 46 | space--; 47 | } 48 | write(1, "0x", 2); 49 | while (format->aux-- > 0) 50 | format->len_str += write(1, "0", 1); 51 | (format->dot == '.' && ch == NULL && format->precision == 0) 52 | ? 0 : ft_memorypointer(ch); 53 | while (space-- > 0) 54 | format->len_str += write(1, " ", 1); 55 | format->len_str -= (format->dot == '.' && ch == NULL && 56 | format->precision == 0) ? 1 : 0; 57 | } 58 | 59 | void ft_display_pointer(t_printf *format, char *ch) 60 | { 61 | unsigned long nb; 62 | int space; 63 | int len; 64 | 65 | len = ft_lenhex_p((unsigned long)ch) + 2; 66 | format->len_str += nb = ft_lenhex_p((unsigned long)ch) + 2; 67 | space = format->width - ((format->precision < len) 68 | ? len : format->precision); 69 | space += (format->dot == '.' && nb == 0 && format->precision == 0) ? 1 : 0; 70 | space += (ch == NULL && format->dot == '.') ? 1 : 0; 71 | format->aux = format->precision - len + 2; 72 | ft_help(space, format, nb, ch); 73 | } 74 | -------------------------------------------------------------------------------- /ft_printf.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_printf.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/02/22 16:58:49 by abello-r #+# #+# */ 9 | /* Updated: 2020/02/22 16:58:59 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libftprintf.h" 14 | 15 | void ft_advance(t_printf *format) 16 | { 17 | if (*format->str == 'd' || *format->str == 'i') 18 | ft_spacex(format, va_arg(format->argptr, int)); 19 | else if (*format->str == 'c') 20 | ft_display_c(format, va_arg(format->argptr, int)); 21 | else if (*format->str == 's') 22 | ft_display_s(format, va_arg(format->argptr, char *)); 23 | else if (*format->str == 'u') 24 | ft_display_u(format, va_arg(format->argptr, unsigned int)); 25 | else if (*format->str == 'x') 26 | ft_display_x(format, va_arg(format->argptr, unsigned int)); 27 | else if (*format->str == 'X') 28 | ft_display_xmayus(format, va_arg(format->argptr, unsigned int)); 29 | else if (*format->str == 'p') 30 | ft_display_pointer(format, va_arg(format->argptr, char *)); 31 | else if (*format->str == '%') 32 | ft_display_c(format, 37); 33 | } 34 | 35 | void ft_formatletter(t_printf *format) 36 | { 37 | format->len_str = 0; 38 | while (*format->str) 39 | { 40 | if (*format->str == '%') 41 | { 42 | ft_setformat(format); 43 | ft_advance(format); 44 | if (*format->str != 'd' && *format->str != 'i' && 45 | *format->str != 'c' && *format->str != 's' && 46 | *format->str != 'u' && *format->str != 'x' && 47 | *format->str != 'X' && *format->str != 'p' && 48 | *format->str != '%') 49 | break ; 50 | } 51 | else 52 | format->len_str += write(1, format->str, 1); 53 | format->str++; 54 | } 55 | va_end(format->argptr); 56 | } 57 | 58 | int ft_printf(const char *s, ...) 59 | { 60 | t_printf format; 61 | 62 | format.str = (char *)s; 63 | va_start(format.argptr, s); 64 | ft_formatletter(&format); 65 | va_end(format.argptr); 66 | return (format.len_str); 67 | } 68 | -------------------------------------------------------------------------------- /ft_setformat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_setformat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/02/21 11:36:35 by abello-r #+# #+# */ 9 | /* Updated: 2020/02/21 11:36:39 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libftprintf.h" 14 | 15 | void ft_pick2(int nb, t_printf *format) 16 | { 17 | if (*format->str == '.') 18 | { 19 | format->dot = '.'; 20 | format->str++; 21 | if (*format->str == '*') 22 | { 23 | format->precision = va_arg(format->argptr, int); 24 | if (format->precision == 0) 25 | format->precision = -1; 26 | } 27 | if (ft_isdigit(*format->str)) 28 | format->precision = ft_atoi(format->str); 29 | } 30 | } 31 | 32 | void ft_pick(int nb, t_printf *format) 33 | { 34 | if (*format->str == '-') 35 | format->tab = '-'; 36 | if (*format->str == '0' && format->width == 0) 37 | format->zero_space = '0'; 38 | if (*format->str == '*') 39 | { 40 | nb = va_arg(format->argptr, int); 41 | format->width = (nb < 0) ? (nb * -1) : nb; 42 | if (nb < 0) 43 | format->tab = '-'; 44 | } 45 | if (ft_isdigit(*format->str) && *format->str != '0' && 46 | format->width == 0 && format->dot != '.') 47 | format->width = ft_atoi(format->str); 48 | ft_pick2(nb, format); 49 | } 50 | 51 | void ft_setformat(t_printf *format) 52 | { 53 | int nb; 54 | 55 | format->width = 0; 56 | format->precision = 0; 57 | format->tab = ' '; 58 | format->zero_space = ' '; 59 | format->dot = ' '; 60 | while (!ft_isalpha(*format->str)) 61 | { 62 | ++format->str; 63 | ft_pick(nb, format); 64 | if (*format->str == '%') 65 | break ; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /libft/Makefile: -------------------------------------------------------------------------------- 1 | SRCS = ft_memset.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 ft_hexa.c ft_hexamayus.c ft_memorypointer.c ft_unsigned_fd.c 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 2 | 3 | OBJS = ${SRCS:.c=.o} 4 | 5 | NAME = libft.a 6 | 7 | CC = cc 8 | RM = rm -f 9 | CFLAGS = -Wall -Werror -Wextra 10 | 11 | .c.o: 12 | ${CC} ${FLAGS} -c $< -o ${<:.c=.o} 13 | 14 | ${NAME}: ${OBJS} 15 | ar rc ${NAME} ${OBJS} 16 | ranlib ${NAME} 17 | 18 | all: ${NAME} 19 | 20 | clean: 21 | ${RM} ${OBJS} 22 | 23 | fclean: clean 24 | ${RM} ${NAME} 25 | 26 | re: fclean 27 | 28 | .PHONY: all clean fclean re 29 | -------------------------------------------------------------------------------- /libft/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/02/16 21:08:05 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] == ' ' || str[i] == '\v' 25 | || 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 | -------------------------------------------------------------------------------- /libft/ft_hexa.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_hexa.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/02/13 17:44:11 by abello-r #+# #+# */ 9 | /* Updated: 2020/02/14 12:30:03 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_hexa(size_t number) 16 | { 17 | size_t n; 18 | 19 | n = number; 20 | if (n >= 16) 21 | ft_hexa(n / 16); 22 | n = n % 16; 23 | n = n < 10 ? n + '0' : n + 87; 24 | ft_putchar_fd(n, 1); 25 | } 26 | -------------------------------------------------------------------------------- /libft/ft_hexamayus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_hexamayus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/02/13 18:36:01 by abello-r #+# #+# */ 9 | /* Updated: 2020/02/14 12:35:37 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_hexamayus(unsigned int number) 16 | { 17 | unsigned int n; 18 | 19 | n = number; 20 | if (n > 16) 21 | ft_hexamayus(n / 16); 22 | n = n % 16; 23 | n = n < 10 ? n + '0' : n + 55; 24 | ft_putchar_fd(n, 1); 25 | } 26 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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/02/15 20:48:59 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 | if (!(x = (char *)malloc(sizeof(char) * (len + 1)))) 50 | return (NULL); 51 | x[len--] = '\0'; 52 | if (n == 0) 53 | x[0] = '0'; 54 | if (n < 0) 55 | { 56 | sign *= -1; 57 | number = n * -1; 58 | x[0] = '-'; 59 | } 60 | else 61 | number = n; 62 | x = ft_array(x, number, len); 63 | return (x); 64 | } 65 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 *lst, void *(*f)(void *), void (*del)(void *)) 16 | { 17 | t_list *x; 18 | t_list *new; 19 | 20 | if (!lst) 21 | return (NULL); 22 | if (!(new = ft_lstnew(f(lst->content)))) 23 | return (NULL); 24 | x = new; 25 | while (lst) 26 | { 27 | if (lst->next) 28 | { 29 | if (!(new->next = ft_lstnew(f(lst->next->content)))) 30 | { 31 | ft_lstclear(&new, del); 32 | return (NULL); 33 | } 34 | new = new->next; 35 | } 36 | lst = lst->next; 37 | } 38 | new->next = NULL; 39 | return (x); 40 | } 41 | -------------------------------------------------------------------------------- /libft/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 | if (!(x = malloc(sizeof(t_list)))) 20 | return (NULL); 21 | x->content = content; 22 | x->next = NULL; 23 | return (x); 24 | } 25 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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/02/13 17:43:04 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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/ft_memorypointer.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memorypointer.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/02/14 11:59:46 by abello-r #+# #+# */ 9 | /* Updated: 2020/02/14 12:45:50 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_memorypointer(char *str) 16 | { 17 | size_t *x; 18 | 19 | x = (size_t *)&str; 20 | ft_hexa(*x); 21 | } 22 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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/02/14 12:45:52 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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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(long n, int fd) 21 | { 22 | int long i; 23 | 24 | i = n; 25 | if (i < 0) 26 | i = i * -1; 27 | if (i > 9) 28 | ft_putnbr_fd(i / 10, fd); 29 | ft_putchar(i % 10 + 48, fd); 30 | } 31 | -------------------------------------------------------------------------------- /libft/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/02/12 16:54:29 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 | size_t x; 19 | 20 | x = ft_strlen(s); 21 | i = -1; 22 | if (!s) 23 | return ; 24 | while (++i < x) 25 | write(fd, &s[i], 1); 26 | } 27 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | if (!(s2 = malloc(i + 1))) 22 | return (NULL); 23 | ft_memcpy(s2, s1, i); 24 | s2[i] = '\0'; 25 | return (s2); 26 | } 27 | -------------------------------------------------------------------------------- /libft/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 | if (!(x = (char *)malloc(sizeof(char) * ft_strlen(s1) + ft_strlen(s2) + 1))) 28 | return (NULL); 29 | while (c1 != ft_strlen(s1)) 30 | { 31 | x[i] = s1[c1]; 32 | ++i && ++c1; 33 | } 34 | while (c2 != ft_strlen(s2)) 35 | { 36 | x[i] = s2[c2]; 37 | ++i && ++c2; 38 | } 39 | x[i] = '\0'; 40 | return (x); 41 | } 42 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | if (!(x = malloc(sizeof(char) * ft_strlen(s) + 1))) 24 | return (NULL); 25 | while (i != ft_strlen(s)) 26 | { 27 | x[i] = (*f)(i, s[i]); 28 | i++; 29 | } 30 | x[i] = '\0'; 31 | return (x); 32 | } 33 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 *haystack, const char *needle, size_t len) 16 | { 17 | size_t c; 18 | 19 | if (*needle == 0 || haystack == needle) 20 | return ((char *)haystack); 21 | c = ft_strlen(needle); 22 | while (*haystack && c <= len--) 23 | { 24 | if (!(ft_strncmp((char *)haystack, (char *)needle, c))) 25 | return ((char *)haystack); 26 | haystack++; 27 | } 28 | return (NULL); 29 | } 30 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | if (!(x = (char *)malloc(sizeof(char) * len + 1))) 28 | return (NULL); 29 | while (i < len) 30 | { 31 | x[i] = s[start + i]; 32 | i++; 33 | } 34 | x[i] = '\0'; 35 | return (x); 36 | } 37 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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/ft_unsigned_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_unsigned_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/02/15 18:31:24 by abello-r #+# #+# */ 9 | /* Updated: 2020/02/15 18:37:29 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_unsigned_fd(int n, int fd) 21 | { 22 | unsigned i; 23 | 24 | i = n; 25 | if (i > 9) 26 | { 27 | ft_unsigned_fd(i / 10, fd); 28 | ft_putchar(i % 10 + 48, fd); 29 | } 30 | else 31 | ft_putchar(i % 10 + 48, fd); 32 | } 33 | -------------------------------------------------------------------------------- /libft/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: 2020/02/16 03:06:32 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 *haystack, 47 | const char *needle, size_t len); 48 | size_t ft_strlcat(char *dst, const char *src, size_t dstsize); 49 | size_t ft_strlcpy(char *dst, const char *src, size_t dstsize); 50 | void *ft_calloc(size_t count, size_t size); 51 | char *ft_strdup(const char *s1); 52 | char *ft_substr(char const *s, unsigned int start, size_t len); 53 | char *ft_strjoin(char const *s1, char const *s2); 54 | char *ft_strtrim(char const *s1, char const *set); 55 | void ft_putchar_fd(char c, int fd); 56 | void ft_putstr_fd(char *s, int fd); 57 | void ft_putendl_fd(char *s, int fd); 58 | void ft_putnbr_fd(long n, int fd); 59 | char *ft_itoa(int n); 60 | char *ft_strmapi(char const *s, char (*f) (unsigned int, char)); 61 | char **ft_split(char const *s, char c); 62 | t_list *ft_lstnew(void *content); 63 | void ft_lstadd_front(t_list **alst, t_list *new); 64 | int ft_lstsize(t_list *lst); 65 | t_list *ft_lstlast(t_list *lst); 66 | void ft_lstadd_back(t_list **lst, t_list *new); 67 | void ft_lstdelone(t_list *lst, void (*del)(void *)); 68 | void ft_lstclear(t_list **lst, void (*del)(void *)); 69 | void ft_lstiter(t_list *lst, void (*f)(void *)); 70 | t_list *ft_lstmap(t_list *lst, void *(*f)(void *) 71 | , void (*del)(void *)); 72 | void ft_hexa(size_t number); 73 | void ft_hexamayus(unsigned int number); 74 | void ft_memorypointer(char *str); 75 | void ft_unsigned_fd(int n, int fd); 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /libftprintf.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* libftprintf.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abello-r +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/02/12 16:47:24 by abello-r #+# #+# */ 9 | /* Updated: 2020/02/19 14:48:28 by abello-r ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LIBFTPRINTF_H 14 | # define LIBFTPRINTF_H 15 | 16 | # include "libft/libft.h" 17 | # include 18 | 19 | typedef struct s_printf 20 | { 21 | char *str; 22 | char zero_space; 23 | char tab; 24 | char dot; 25 | int width; 26 | int precision; 27 | int len_str; 28 | int aux; 29 | va_list argptr; 30 | } t_printf; 31 | 32 | size_t ft_intlen(long nb); 33 | int ft_printf(const char *s, ...); 34 | void ft_spacex(t_printf *format, int nb); 35 | void ft_formatletter(t_printf *format); 36 | void ft_setformat(t_printf *format); 37 | void ft_display_c(t_printf *format, int nb); 38 | void ft_display_s(t_printf *format, char *str); 39 | void ft_display_u(t_printf *format, unsigned int nb); 40 | void ft_display_x(t_printf *format, unsigned int nb); 41 | void ft_display_xmayus(t_printf *format, unsigned int nb); 42 | void ft_display_pointer(t_printf *ft_format, char *ch); 43 | 44 | #endif 45 | --------------------------------------------------------------------------------