v2
This commit is contained in:
		
							
								
								
									
										60
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										60
									
								
								Makefile
									
									
									
									
									
								
							| @ -6,7 +6,7 @@ | ||||
| #    By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+         # | ||||
| #                                                 +#+#+#+#+#+   +#+            # | ||||
| #    Created: 2022/09/27 08:39:27 by cchauvet          #+#    #+#              # | ||||
| #    Updated: 2022/09/27 17:11:15 by cchauvet         ###   ########.fr        # | ||||
| #    Updated: 2022/10/04 14:19:21 by cchauvet         ###   ########.fr        # | ||||
| #                                                                              # | ||||
| # **************************************************************************** # | ||||
|  | ||||
| @ -17,6 +17,8 @@ SRCS = ft_isalpha.c \ | ||||
| 	   ft_isprint.c \ | ||||
| 	   ft_strlen.c \ | ||||
| 	   ft_memset.c \ | ||||
| 	   ft_strdup.c \ | ||||
| 	   ft_strndup.c \ | ||||
| 	   ft_bzero.c \ | ||||
| 	   ft_toupper.c \ | ||||
| 	   ft_tolower.c \ | ||||
| @ -27,35 +29,65 @@ SRCS = ft_isalpha.c \ | ||||
| 	   ft_memmove.c \ | ||||
| 	   ft_memchr.c \ | ||||
| 	   ft_memcmp.c \ | ||||
| 	   ft_strdup.c \ | ||||
| 	   ft_strnstr.c \ | ||||
| 	   ft_strlcat.c \ | ||||
| 	   ft_atoi.c \ | ||||
| 	   ft_memccpy.c \ | ||||
| 	   ft_calloc.c \ | ||||
| 	   ft_strlcpy.c | ||||
| 	   ft_strlcpy.c \ | ||||
| 	   ft_substr.c \ | ||||
| 	   ft_strjoin.c \ | ||||
| 	   ft_strtrim.c \ | ||||
| 	   ft_itoa.c \ | ||||
| 	   ft_split.c \ | ||||
| 	   ft_strmapi.c \ | ||||
| 	   ft_striteri.c \ | ||||
| 	   ft_putchar_fd.c \ | ||||
| 	   ft_putstr_fd.c \ | ||||
| 	   ft_putendl_fd.c \ | ||||
| 	   ft_putnbr_fd.c \ | ||||
|  | ||||
| BSRCS = ft_lstnew.c \ | ||||
| 	   ft_lstadd_front.c \ | ||||
| 	   ft_lstsize.c \ | ||||
| 	   ft_lstlast.c \ | ||||
| 	   ft_lstadd_back.c \ | ||||
| 	   ft_lstdelone.c \ | ||||
| 	   ft_lstclear.c \ | ||||
| 	   ft_lstiter.c \ | ||||
| 	   ft_lstmap.c | ||||
|  | ||||
| OBJS = ${SRCS:.c=.o} | ||||
|  | ||||
| BOBJS = ${BSRCS:.c=.o} | ||||
|  | ||||
| NAME = libft | ||||
|  | ||||
| CFLAG = -Wall -Werror -Wextra | ||||
|  | ||||
| all: | ||||
| 	gcc -c ${CFLAG} ${SRCS} | ||||
| 	ar rc ${NAME}.a ${OBJS} | ||||
| all: ${NAME} | ||||
|  | ||||
| ${NAME}: ${OBJS} | ||||
| 	ar -rc ${NAME}.a ${OBJS} | ||||
|  | ||||
| bonus: ${OBJS} ${BOJS} | ||||
| 	ar -rc ${NAME} ${OBJS} ${BOBJS} | ||||
|  | ||||
| %.o: %.c libft.h | ||||
| 	${CC} ${CFLAGS} -c -o $@ $< | ||||
| 	 | ||||
| clean: | ||||
| 	rm -f ${OBJS} | ||||
|  | ||||
| fclean: | ||||
| 	rm -f ${OBJS} | ||||
| fclean: clean | ||||
| 	rm -f ${NAME}.a | ||||
|  | ||||
| re: | ||||
| 	rm -f ${OBJS} | ||||
| 	rm -f ${NAME}.a | ||||
| 	gcc -c ${CFLAG} ${SRCS} | ||||
| 	ar rc ${NAME}.a ${OBJS} | ||||
| re: fclean all | ||||
|  | ||||
| .PHONY: bonus clean fclean re | ||||
|  | ||||
| test: fclean | ||||
| 	rm -f a.out | ||||
| 	gcc ${CFLAGS} -g ${SRCS} ${BSRCS} main.c | ||||
|  | ||||
| so: | ||||
| 	gcc -nostartfiles -fPIC $(CFLAG) $(SRCS) | ||||
|  | ||||
							
								
								
									
										10
									
								
								ft_atoi.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								ft_atoi.c
									
									
									
									
									
								
							| @ -6,7 +6,7 @@ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/27 16:14:34 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/27 16:45:19 by cchauvet         ###   ########.fr       */ | ||||
| /*   Updated: 2022/09/28 18:15:04 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| @ -20,12 +20,14 @@ int	ft_atoi(const char *nptr) | ||||
|  | ||||
| 	str = (char *) nptr; | ||||
| 	out = 0; | ||||
| 	while (*str == ' ') | ||||
| 	while (*str == ' ' || *str == '\f' || *str == '\v' || *str == '\t' | ||||
| 		|| *str == '\r' || *str == '\n') | ||||
| 		str++; | ||||
| 	sign = 1; | ||||
| 	if (*str == '-') | ||||
| 	if (*str == '-' || *str == '+') | ||||
| 	{ | ||||
| 		sign = -1; | ||||
| 		if (*str == '-') | ||||
| 			sign = -1; | ||||
| 		str++; | ||||
| 	} | ||||
| 	while (ft_isdigit(*str)) | ||||
|  | ||||
| @ -6,19 +6,19 @@ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/27 16:09:01 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/27 16:12:30 by cchauvet         ###   ########.fr       */ | ||||
| /*   Updated: 2022/09/28 16:27:52 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| void	*calloc(size_t nmemb, size_t size) | ||||
| void	*ft_calloc(size_t nmemb, size_t size) | ||||
| { | ||||
| 	char	*tab; | ||||
|  | ||||
| 	if (nmemb * size == 0) | ||||
| 		return (NULL); | ||||
| 	tab = malloc(nmemb * size); | ||||
| 	if (tab == NULL) | ||||
| 		return (NULL); | ||||
| 	ft_bzero(tab, nmemb * size); | ||||
| 	return (tab); | ||||
| } | ||||
|  | ||||
| @ -6,7 +6,7 @@ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/26 11:52:31 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/27 15:46:02 by cchauvet         ###   ########.fr       */ | ||||
| /*   Updated: 2022/09/28 15:05:17 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| @ -14,5 +14,5 @@ | ||||
|  | ||||
| int	ft_isprint(int c) | ||||
| { | ||||
| 	return (32 <= c && c <= 127); | ||||
| 	return (32 <= c && c < 127); | ||||
| } | ||||
|  | ||||
							
								
								
									
										55
									
								
								ft_itoa.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								ft_itoa.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,55 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_itoa.c                                          :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/29 13:49:45 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/29 18:07:15 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| static int	ft_nb_digit(int n) | ||||
| { | ||||
| 	int	out; | ||||
|  | ||||
| 	out = 0; | ||||
| 	while (n) | ||||
| 	{ | ||||
| 		n /= 10; | ||||
| 		out++; | ||||
| 	} | ||||
| 	return (out); | ||||
| } | ||||
|  | ||||
| char	*ft_itoa(int n) | ||||
| { | ||||
| 	char			*out; | ||||
| 	unsigned int	nb[2]; | ||||
|  | ||||
| 	if (!n) | ||||
| 		return (ft_strdup("0")); | ||||
| 	nb[0] = ft_nb_digit(n); | ||||
| 	if (n < 0) | ||||
| 	{ | ||||
| 		nb[1] = -n; | ||||
| 		nb[0]++; | ||||
| 	} | ||||
| 	else | ||||
| 		nb[1] = n; | ||||
| 	out = malloc(sizeof(char) * (nb[0] + 1)); | ||||
| 	if (out == NULL) | ||||
| 		return (NULL); | ||||
| 	out[nb[0]--] = 0; | ||||
| 	if (n < 0) | ||||
| 		out[0] = '-'; | ||||
| 	while (nb[1]) | ||||
| 	{ | ||||
| 		out[nb[0]--] = nb[1] % 10 + 48; | ||||
| 		nb[1] /= 10; | ||||
| 	} | ||||
| 	return (out); | ||||
| } | ||||
| @ -1,26 +1,26 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_memccpy.c                                       :+:      :+:    :+:   */ | ||||
| /*   ft_lstadd_back.c                                   :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/27 16:53:36 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/27 17:21:51 by cchauvet         ###   ########.fr       */ | ||||
| /*   Created: 2022/09/29 23:58:34 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/10/04 14:06:22 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
| #include "libft.h" | ||||
| 
 | ||||
| void	*memccpy(void *dest, const void *src, int c, size_t n) | ||||
| void	ft_lstadd_back(t_list **lst, t_list *new) | ||||
| { | ||||
| 	int		*tab; | ||||
| 	size_t	max; | ||||
| 	t_list	*last; | ||||
| 
 | ||||
| 	tab = (int *) src; | ||||
| 	while (max < ft_strlen((char *) tab) && tab[max] == c) | ||||
| 		max++; | ||||
| 	if (max < n) | ||||
| 		max = n; | ||||
| 	return (ft_memcpy(dest, src, max)); | ||||
| 	if (lst == NULL || new == NULL) | ||||
| 		return ; | ||||
| 	last = ft_lstlast(*lst); | ||||
| 	if (last == NULL) | ||||
| 		*lst = new; | ||||
| 	else | ||||
| 		last->next = new; | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								ft_lstadd_back.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_lstadd_back.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										21
									
								
								ft_lstadd_front.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								ft_lstadd_front.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,21 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_lstadd_front.c                                  :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/29 23:50:03 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/30 01:08:27 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| void	ft_lstadd_front(t_list **lst, t_list *new) | ||||
| { | ||||
| 	if (new == NULL) | ||||
| 		return ; | ||||
| 	new->next = *lst; | ||||
| 	*lst = new; | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								ft_lstadd_front.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_lstadd_front.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										27
									
								
								ft_lstclear.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								ft_lstclear.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_lstclear.c                                      :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/30 00:01:05 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/30 01:34:44 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| void	ft_lstclear(t_list **lst, void (*del)(void *)) | ||||
| { | ||||
| 	t_list	*next; | ||||
|  | ||||
| 	if (lst == NULL || del == NULL) | ||||
| 		return ; | ||||
| 	while (*lst == NULL) | ||||
| 	{ | ||||
| 		next = (*lst)->next; | ||||
| 		ft_lstdelone(*lst, del); | ||||
| 		*lst = next; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								ft_lstclear.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_lstclear.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										25
									
								
								ft_lstdelone.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								ft_lstdelone.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,25 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_lstdelone.c                                     :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/30 00:02:55 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/30 01:26:24 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| void	ft_lstdelone(t_list *lst, void (*del)(void *)) | ||||
| { | ||||
| 	if (lst == NULL || lst == NULL) | ||||
| 		return ; | ||||
| 	if (lst != NULL) | ||||
| 	{ | ||||
| 		if (lst->content != NULL) | ||||
| 			del(lst->content); | ||||
| 		free(lst); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								ft_lstdelone.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_lstdelone.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										22
									
								
								ft_lstiter.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								ft_lstiter.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_lstiter.c                                       :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/30 00:05:43 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/30 00:33:06 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| void	ft_lstiter(t_list *lst, void (*f)(void *)) | ||||
| { | ||||
| 	while (lst->next == NULL) | ||||
| 	{ | ||||
| 		f(lst); | ||||
| 		lst = lst->next; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								ft_lstiter.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_lstiter.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										22
									
								
								ft_lstlast.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								ft_lstlast.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_lstlast.c                                       :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/29 23:55:52 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/30 01:20:18 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| t_list	*ft_lstlast(t_list *lst) | ||||
| { | ||||
| 	if (lst == NULL) | ||||
| 		return (NULL); | ||||
| 	while (lst->next != NULL) | ||||
| 		lst = lst->next; | ||||
| 	return (lst); | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								ft_lstlast.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_lstlast.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										13
									
								
								ft_lstmap.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								ft_lstmap.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_lstmap.c                                        :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/30 00:05:05 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/10/04 14:10:47 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
							
								
								
									
										
											BIN
										
									
								
								ft_lstmap.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_lstmap.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										25
									
								
								ft_lstnew.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								ft_lstnew.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,25 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_lstnew.c                                        :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/29 23:41:40 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/29 23:47:50 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| t_list	*ft_lstnew(void *content) | ||||
| { | ||||
| 	t_list	*new; | ||||
|  | ||||
| 	new = malloc(sizeof(t_list)); | ||||
| 	if (new == NULL) | ||||
| 		return (NULL); | ||||
| 	new->next = NULL; | ||||
| 	new->content = content; | ||||
| 	return (new); | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								ft_lstnew.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_lstnew.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										26
									
								
								ft_lstsize.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								ft_lstsize.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_lstsize.c                                       :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/30 01:18:08 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/30 01:18:15 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| int	ft_lstsize(t_list *lst) | ||||
| { | ||||
| 	int	count; | ||||
|  | ||||
| 	count = 0; | ||||
| 	while (lst != NULL) | ||||
| 	{ | ||||
| 		count++; | ||||
| 		lst = lst->next; | ||||
| 	} | ||||
| 	return (count); | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								ft_lstsize.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ft_lstsize.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										10
									
								
								ft_memcpy.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								ft_memcpy.c
									
									
									
									
									
								
							| @ -6,7 +6,7 @@ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/27 09:42:11 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/27 15:07:20 by cchauvet         ###   ########.fr       */ | ||||
| /*   Updated: 2022/09/29 11:50:17 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| @ -18,15 +18,15 @@ void	*ft_memcpy(void *dest, const void *src, size_t n) | ||||
| 	char	*tab2; | ||||
| 	size_t	i; | ||||
|  | ||||
| 	if (dest == NULL || src == NULL) | ||||
| 		return (NULL); | ||||
| 	if (dest == NULL && src == NULL) | ||||
| 		return (dest); | ||||
| 	tab1 = dest; | ||||
| 	tab2 = (void *) src; | ||||
| 	i = 0; | ||||
| 	while (i < n) | ||||
| 	{ | ||||
| 			tab1[i] = tab2[i]; | ||||
| 			i++; | ||||
| 		tab1[i] = tab2[i]; | ||||
| 		i++; | ||||
| 	} | ||||
| 	return (tab1); | ||||
| } | ||||
|  | ||||
| @ -6,7 +6,7 @@ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/27 11:44:12 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/27 14:14:24 by cchauvet         ###   ########.fr       */ | ||||
| /*   Updated: 2022/09/28 16:40:24 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| @ -18,6 +18,8 @@ void	*ft_memmove(void *dest, const void *src, size_t n) | ||||
| 	char	*tab1; | ||||
| 	char	*tab2; | ||||
|  | ||||
| 	if (dest == NULL && src == NULL) | ||||
| 		return (dest); | ||||
| 	tab1 = dest; | ||||
| 	tab2 = (void *) src; | ||||
| 	if (tab1 < tab2) | ||||
|  | ||||
							
								
								
									
										18
									
								
								ft_putchar_fd.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								ft_putchar_fd.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,18 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_putchar_fd.c                                    :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/29 22:23:35 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/29 22:24:53 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| void	ft_putchar_fd(char c, int fd) | ||||
| { | ||||
| 	write(fd, &c, 1); | ||||
| } | ||||
							
								
								
									
										21
									
								
								ft_putendl_fd.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								ft_putendl_fd.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,21 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_putendl_fd.c                                    :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/29 22:26:36 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/29 22:43:19 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| void	ft_putendl_fd(char *s, int fd) | ||||
| { | ||||
| 	if (s == NULL) | ||||
| 		return ; | ||||
| 	ft_putstr_fd(s, fd); | ||||
| 	ft_putchar_fd('\n', fd); | ||||
| } | ||||
							
								
								
									
										34
									
								
								ft_putnbr_fd.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								ft_putnbr_fd.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,34 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_putnbr_fd.c                                     :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/29 22:28:27 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/29 22:39:25 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| void	ft_putnbr_fd(int n, int fd) | ||||
| { | ||||
| 	if (n == -2147483648) | ||||
| 	{ | ||||
| 		ft_putnbr_fd(-2, fd); | ||||
| 		ft_putnbr_fd(147483648, fd); | ||||
| 	} | ||||
| 	else if (n < 0) | ||||
| 	{ | ||||
| 		ft_putchar_fd('-', fd); | ||||
| 		ft_putnbr_fd(-n, fd); | ||||
| 	} | ||||
| 	else if (n > 9) | ||||
| 	{ | ||||
| 		ft_putnbr_fd(n / 10, fd); | ||||
| 		ft_putnbr_fd(n % 10, fd); | ||||
| 	} | ||||
| 	else | ||||
| 		ft_putchar_fd(n + 48, fd); | ||||
| } | ||||
							
								
								
									
										21
									
								
								ft_putstr_fd.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								ft_putstr_fd.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,21 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_putstr_fd.c                                     :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/29 22:25:08 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/29 22:40:34 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| void	ft_putstr_fd(char *s, int fd) | ||||
| { | ||||
| 	if (s == NULL) | ||||
| 		return ; | ||||
| 	while (*s) | ||||
| 		write(fd, s++, 1); | ||||
| } | ||||
							
								
								
									
										96
									
								
								ft_split.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										96
									
								
								ft_split.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,96 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_split.c                                         :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/29 17:37:50 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/10/04 13:53:25 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| static size_t	ft_seglen(const char *s, char c) | ||||
| { | ||||
| 	size_t	len; | ||||
| 	size_t	i; | ||||
|  | ||||
| 	len = 1; | ||||
| 	i = 0; | ||||
| 	while (s[i]) | ||||
| 	{ | ||||
| 		while (s[i] == c && s[i]) | ||||
| 			i++; | ||||
| 		if (s[i]) | ||||
| 			len++; | ||||
| 		while (s[i] != c && s[i]) | ||||
| 			i++; | ||||
| 	} | ||||
| 	return (len); | ||||
| } | ||||
|  | ||||
| static void	*ft_cancel(size_t len, char **tab) | ||||
| { | ||||
| 	size_t	i; | ||||
|  | ||||
| 	i = 0; | ||||
| 	while (i < len) | ||||
| 	{ | ||||
| 		free(tab[i]); | ||||
| 		i++; | ||||
| 	} | ||||
| 	free(tab); | ||||
| 	return (NULL); | ||||
| } | ||||
|  | ||||
| static char	**ft_segmentator(const char *s, char c, size_t len, char **tab) | ||||
| { | ||||
| 	size_t	i; | ||||
| 	size_t	j; | ||||
| 	ssize_t	start; | ||||
|  | ||||
| 	if (tab == NULL) | ||||
| 		return (NULL); | ||||
| 	i = 0; | ||||
| 	j = 0; | ||||
| 	while (i < len) | ||||
| 	{ | ||||
| 		while (s[j] == c) | ||||
| 			j++; | ||||
| 		start = j; | ||||
| 		while (s[j] != c) | ||||
| 			j++; | ||||
| 		tab[i] = ft_strndup(s + start, j - start); | ||||
| 		if (tab[i] == NULL) | ||||
| 			return (ft_cancel(len, tab)); | ||||
| 		i++; | ||||
| 	} | ||||
| 	return (tab); | ||||
| } | ||||
|  | ||||
| char	**ft_split(const char *s, char c) | ||||
| { | ||||
| 	char	**tab; | ||||
| 	size_t	len; | ||||
|  | ||||
| 	if (s == NULL) | ||||
| 		return (NULL); | ||||
| 	len = ft_seglen(s, c); | ||||
| 	tab = malloc (sizeof(char *) * len); | ||||
| 	if (tab == NULL) | ||||
| 		return (NULL); | ||||
| 	if (c == 0) | ||||
| 	{ | ||||
| 		tab[0] = ft_strdup(s); | ||||
| 		if (tab[0] == NULL) | ||||
| 			return (NULL); | ||||
| 	} | ||||
| 	else | ||||
| 		tab = ft_segmentator(s, c, len - 1, tab); | ||||
| 	if (tab == NULL) | ||||
| 		return (NULL); | ||||
| 	tab[len - 1] = NULL; | ||||
| 	return (tab); | ||||
| } | ||||
| @ -6,15 +6,15 @@ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/26 14:44:15 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/27 11:30:30 by cchauvet         ###   ########.fr       */ | ||||
| /*   Updated: 2022/09/28 16:49:07 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| char	*strchr(const char *s, int c) | ||||
| char	*ft_strchr(const char *s, int c) | ||||
| { | ||||
| 	while (*s) | ||||
| 	while (*s || *s == c) | ||||
| 	{ | ||||
| 		if (*s == c) | ||||
| 			return ((char *) s); | ||||
|  | ||||
							
								
								
									
										14
									
								
								ft_strdup.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								ft_strdup.c
									
									
									
									
									
								
							| @ -6,24 +6,24 @@ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/27 16:00:49 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/27 16:07:00 by cchauvet         ###   ########.fr       */ | ||||
| /*   Updated: 2022/09/29 11:03:42 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| char	*strdup(const char *s) | ||||
| char	*ft_strdup(const char *s) | ||||
| { | ||||
| 	char	*in; | ||||
| 	char	*out; | ||||
| 	size_t	i; | ||||
|  | ||||
| 	in = (char *) s; | ||||
| 	out = malloc(sizeof(char) * (ft_strlen(in) + 1)); | ||||
| 	out = malloc(sizeof(char) * (ft_strlen(s) + 1)); | ||||
| 	if (out == NULL) | ||||
| 		return (NULL); | ||||
| 	i = 0; | ||||
| 	while (in[i]) | ||||
| 	while (s[i]) | ||||
| 	{ | ||||
| 		out[i] = in[i]; | ||||
| 		out[i] = s[i]; | ||||
| 		i++; | ||||
| 	} | ||||
| 	out[i] = 0; | ||||
|  | ||||
							
								
								
									
										25
									
								
								ft_striteri.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								ft_striteri.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,25 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_striteri.c                                      :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/29 22:21:01 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/29 22:36:33 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| void	ft_striteri(char *s, void (*f)(unsigned int, char *)) | ||||
| { | ||||
| 	size_t	i; | ||||
|  | ||||
| 	i = 0; | ||||
| 	while (s[i]) | ||||
| 	{ | ||||
| 		f(i, s + i); | ||||
| 		i++; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										38
									
								
								ft_strjoin.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								ft_strjoin.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,38 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_strjoin.c                                       :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/29 11:20:27 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/29 11:30:50 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| char	*ft_strjoin(const char *s1, const char *s2) | ||||
| { | ||||
| 	char	*out; | ||||
| 	ssize_t	i; | ||||
| 	ssize_t	j; | ||||
| 	size_t	len_s1; | ||||
| 	size_t	len_s2; | ||||
|  | ||||
| 	if (s1 == NULL || s2 == NULL) | ||||
| 		return (NULL); | ||||
| 	len_s1 = ft_strlen(s1); | ||||
| 	len_s2 = ft_strlen(s2); | ||||
| 	out = malloc(sizeof(char) * (len_s1 + len_s2 + 1)); | ||||
| 	if (out == NULL) | ||||
| 		return (NULL); | ||||
| 	i = -1; | ||||
| 	while (++i < (ssize_t) len_s1) | ||||
| 		out[i] = s1[i]; | ||||
| 	j = -1; | ||||
| 	while (++j < (ssize_t) len_s2) | ||||
| 		out[j + i] = s2[j]; | ||||
| 	out[i + j] = 0; | ||||
| 	return (out); | ||||
| } | ||||
							
								
								
									
										27
									
								
								ft_strlcat.c
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								ft_strlcat.c
									
									
									
									
									
								
							| @ -6,29 +6,20 @@ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/27 17:02:13 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/27 17:23:07 by cchauvet         ###   ########.fr       */ | ||||
| /*   Updated: 2022/09/28 17:11:29 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| char	*strlcat(char *dst, const char *src, size_t size) | ||||
| size_t	ft_strlcat(char *dest, const char *src, size_t size) | ||||
| { | ||||
| 	size_t	max; | ||||
| 	char	*str; | ||||
| 	int		i; | ||||
| 	size_t	len_dest; | ||||
|  | ||||
| 	str = (char *) src; | ||||
| 	max = size; | ||||
| 	if (ft_strlen(str) > max) | ||||
| 		max = ft_strlen(str); | ||||
| 	if (ft_strlen(dst) > max) | ||||
| 		max = ft_strlen(dst); | ||||
| 	i = 0; | ||||
| 	while (i < max) | ||||
| 	{ | ||||
| 		dst[i] = str[i]; | ||||
| 		i++; | ||||
| 	} | ||||
| 	return (dst); | ||||
| 	if (size == 0) | ||||
| 		return (ft_strlen(src)); | ||||
| 	len_dest = ft_strlen(dest); | ||||
| 	if (len_dest >= size) | ||||
| 		return (ft_strlen(src) + (size)); | ||||
| 	return (len_dest + ft_strlcpy(dest + len_dest, src, size - len_dest)); | ||||
| } | ||||
|  | ||||
							
								
								
									
										13
									
								
								ft_strlcpy.c
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								ft_strlcpy.c
									
									
									
									
									
								
							| @ -6,24 +6,23 @@ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/27 16:24:15 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/27 16:29:08 by cchauvet         ###   ########.fr       */ | ||||
| /*   Updated: 2022/09/28 17:23:27 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| char	*strlcpy(char *dst, const char *src, size_t size) | ||||
| size_t	ft_strlcpy(char *dst, const char *src, size_t size) | ||||
| { | ||||
| 	char	*str; | ||||
| 	size_t	i; | ||||
|  | ||||
| 	i = 0; | ||||
| 	str = (char *) src; | ||||
| 	while (str[i + 1] && dst[i + 1] && i < size - 1) | ||||
| 	while (i + 1 < size && src[i]) | ||||
| 	{ | ||||
| 		dst[i] = src[i]; | ||||
| 		i++; | ||||
| 	} | ||||
| 	dst[i] = 0; | ||||
| 	return (dst); | ||||
| 	if (size) | ||||
| 		dst[i] = 0; | ||||
| 	return (ft_strlen(src)); | ||||
| } | ||||
|  | ||||
							
								
								
									
										33
									
								
								ft_strmapi.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								ft_strmapi.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,33 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_strmapi.c                                       :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/29 22:01:18 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/30 00:53:55 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| char	*ft_strmapi(char const *s, char (*f)(unsigned int, char)) | ||||
| { | ||||
| 	char	*out; | ||||
| 	size_t	i; | ||||
|  | ||||
| 	if (s == NULL) | ||||
| 		return (NULL); | ||||
| 	out = malloc((ft_strlen(s) + 1) * sizeof(char)); | ||||
| 	if (out == NULL) | ||||
| 		return (NULL); | ||||
| 	i = 0; | ||||
| 	while (s[i]) | ||||
| 	{ | ||||
| 		out[i] = f(i, s[i]); | ||||
| 		i++; | ||||
| 	} | ||||
| 	out[i] = 0; | ||||
| 	return (out); | ||||
| } | ||||
| @ -6,18 +6,20 @@ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/27 08:30:26 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/27 08:36:25 by cchauvet         ###   ########.fr       */ | ||||
| /*   Updated: 2022/09/28 17:29:56 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| int	strncmp(const char *s1, const char *s2, size_t n) | ||||
| int	ft_strncmp(const char *s1, const char *s2, size_t n) | ||||
| { | ||||
| 	size_t	i; | ||||
|  | ||||
| 	if (n == 0) | ||||
| 		return (0); | ||||
| 	i = 0; | ||||
| 	while (s1[i] == s2[i] && i < n - 1 && s1[i] && s2[i]) | ||||
| 		i++; | ||||
| 	return (s1[i] - s2[i]); | ||||
| 	return ((unsigned char) s1[i] - (unsigned char) s2[i]); | ||||
| } | ||||
|  | ||||
							
								
								
									
										31
									
								
								ft_strndup.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								ft_strndup.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,31 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_strndup.c                                       :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/29 10:33:40 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/29 11:03:02 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| char	*ft_strndup(const char *s, size_t n) | ||||
| { | ||||
| 	char	*out; | ||||
| 	size_t	i; | ||||
|  | ||||
| 	out = malloc((n + 1) * sizeof(char)); | ||||
| 	if (out == NULL) | ||||
| 		return (NULL); | ||||
| 	i = 0; | ||||
| 	while (i < n && *s) | ||||
| 	{ | ||||
| 		out[i] = s[i]; | ||||
| 		i++; | ||||
| 	} | ||||
| 	out[i] = 0; | ||||
| 	return (out); | ||||
| } | ||||
| @ -1,31 +1,35 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_strstr.c                                        :+:      :+:    :+:   */ | ||||
| /*   ft_strnstr.c                                       :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/26 13:39:33 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/26 15:11:03 by cchauvet         ###   ########.fr       */ | ||||
| /*   Updated: 2022/09/29 21:10:21 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
| #include "lib_ft.h" | ||||
| #include "libft.h" | ||||
| 
 | ||||
| char	*strstr(const char *haystack, const char *needle) | ||||
| char	*ft_strnstr(const char *big, const char *little, size_t len) | ||||
| { | ||||
| 	int	i; | ||||
| 	size_t	i; | ||||
| 	size_t	j; | ||||
| 
 | ||||
| 	if (!*needle) | ||||
| 		return (haystack); | ||||
| 	while (*haystack) | ||||
| 	if (!*little || (little == big && ft_strlen(little) <= len)) | ||||
| 		return ((char *) big); | ||||
| 	i = 0; | ||||
| 	while (i < len && big[i]) | ||||
| 	{ | ||||
| 		i = 0; | ||||
| 		while (*(haystack + i) == *(needle + i)) | ||||
| 			i++; | ||||
| 		if (!*(haystack + i)) | ||||
| 			return (needle); | ||||
| 		str++; | ||||
| 		j = 0; | ||||
| 		while (big[i + j] == little[j] && i + j < len) | ||||
| 		{ | ||||
| 			if (!little[j + 1]) | ||||
| 				return ((char *) big + i); | ||||
| 			j++; | ||||
| 		} | ||||
| 		i++; | ||||
| 	} | ||||
| 	return (NULL); | ||||
| } | ||||
							
								
								
									
										18
									
								
								ft_strrchr.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								ft_strrchr.c
									
									
									
									
									
								
							| @ -6,22 +6,22 @@ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/27 08:25:33 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/27 11:29:58 by cchauvet         ###   ########.fr       */ | ||||
| /*   Updated: 2022/09/28 17:26:42 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| char	*strrchr(const char *s, int c) | ||||
| char	*ft_strrchr(const char *s, int c) | ||||
| { | ||||
| 	char	*ret; | ||||
| 	size_t	i; | ||||
|  | ||||
| 	ret = NULL; | ||||
| 	while (*s) | ||||
| 	i = ft_strlen((char *) s); | ||||
| 	while (i > 0 || s[i] == c) | ||||
| 	{ | ||||
| 		if (*s == (char) c) | ||||
| 			ret = (char *) s; | ||||
| 		s++; | ||||
| 		if (s[i] == c) | ||||
| 			return ((char *) &s[i]); | ||||
| 		i--; | ||||
| 	} | ||||
| 	return (ret); | ||||
| 	return (NULL); | ||||
| } | ||||
|  | ||||
							
								
								
									
										15
									
								
								ft_strteri.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								ft_strteri.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_strteri.c                                       :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/29 22:16:27 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/29 22:17:02 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| void	ft_striteri(char *s, void (*f)(unsigned int, char *)); | ||||
							
								
								
									
										44
									
								
								ft_strtrim.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								ft_strtrim.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,44 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_strtrim.c                                       :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/29 11:33:53 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/29 18:03:20 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| static int	ft_is_in(const char c, const char *charset) | ||||
| { | ||||
| 	while (*charset) | ||||
| 	{ | ||||
| 		if (c == *charset) | ||||
| 			return (1); | ||||
| 		charset++; | ||||
| 	} | ||||
| 	return (0); | ||||
| } | ||||
|  | ||||
| char	*ft_strtrim(const char *s1, const char *set) | ||||
| { | ||||
| 	size_t	start; | ||||
| 	size_t	stop; | ||||
| 	char	*str; | ||||
|  | ||||
| 	if (s1 == NULL || set == NULL) | ||||
| 		return (NULL); | ||||
| 	if (!*s1 || !*s1) | ||||
| 		return (ft_strdup("")); | ||||
| 	start = 0; | ||||
| 	while (ft_is_in(s1[start], set)) | ||||
| 		start++; | ||||
| 	stop = ft_strlen(s1) - 1; | ||||
| 	while (ft_is_in(s1[stop], set)) | ||||
| 		stop--; | ||||
| 	str = ft_substr(s1, start, stop - start + 1); | ||||
| 	return (str); | ||||
| } | ||||
							
								
								
									
										31
									
								
								ft_substr.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								ft_substr.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,31 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   ft_substr.c                                        :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/28 18:53:44 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/29 18:03:00 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| char	*ft_substr(const char *s, unsigned int start, size_t len) | ||||
| { | ||||
| 	size_t	max; | ||||
| 	char	*sub; | ||||
|  | ||||
| 	if (s == NULL || !*s) | ||||
| 		return (NULL); | ||||
| 	max = ft_strlen(s); | ||||
| 	if (max > len) | ||||
| 		max = len; | ||||
| 	if (start >= ft_strlen(s)) | ||||
| 		return (ft_strdup("")); | ||||
| 	sub = ft_strndup(s + start, max); | ||||
| 	if (sub == NULL) | ||||
| 		return (NULL); | ||||
| 	return (sub); | ||||
| } | ||||
							
								
								
									
										10
									
								
								ft_tolower.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								ft_tolower.c
									
									
									
									
									
								
							| @ -5,16 +5,14 @@ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/26 13:25:48 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/27 11:18:32 by cchauvet         ###   ########.fr       */ | ||||
| /*   Created: 2022/09/26 12:38:07 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/28 16:41:24 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include "libft.h" | ||||
|  | ||||
| int	ft_lower(int c) | ||||
| int	ft_tolower(int c) | ||||
| { | ||||
| 	if (c >= 'A' && 'Z' >= c) | ||||
| 		return (c - 48); | ||||
| 	return (c); | ||||
| 	return (c - ('A' - 'a') * (c >= 'A' && 'Z' >= c)); | ||||
| } | ||||
|  | ||||
| @ -6,7 +6,7 @@ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/26 12:38:07 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/27 11:04:06 by cchauvet         ###   ########.fr       */ | ||||
| /*   Updated: 2022/09/28 15:08:58 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| @ -14,7 +14,5 @@ | ||||
|  | ||||
| int	ft_toupper(int c) | ||||
| { | ||||
| 	if (c >= 'a' && 'z' >= c) | ||||
| 		return (c - 48); | ||||
| 	return (c); | ||||
| 	return (c + ('A' - 'a') * (c >= 'a' && 'z' >= c)); | ||||
| } | ||||
|  | ||||
							
								
								
									
										37
									
								
								libft.h
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								libft.h
									
									
									
									
									
								
							| @ -6,22 +6,30 @@ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/09/26 14:47:54 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/09/27 16:06:28 by cchauvet         ###   ########.fr       */ | ||||
| /*   Updated: 2022/10/04 13:45:02 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #ifndef LIBFT_H | ||||
| # define LIBFT_H | ||||
| # include <stddef.h> | ||||
| # include <stdlib.h> | ||||
| # include <unistd.h> | ||||
|  | ||||
| typedef struct s_list | ||||
| { | ||||
| 	void			*content; | ||||
| 	struct s_list	*next; | ||||
| }	t_list; | ||||
|  | ||||
| char	*ft_strdup(const char *s); | ||||
| char	*ft_strndup(const char *s, size_t n); | ||||
| void	*ft_calloc(size_t nmemb, size_t size); | ||||
| int		ft_isalpha(int c); | ||||
| int		ft_isdigit(int c); | ||||
| int		ft_isalnum(int c); | ||||
| int		ft_isascii(int c); | ||||
| int		ft_isprint(int c); | ||||
| size_t	ft_strlen(const char *s); | ||||
| /* todo */ | ||||
| void	*ft_memset(void *s, int c, size_t n); | ||||
| void	ft_bzero(void *s, size_t n); | ||||
| void	*ft_memcpy(void *dest, const void *src, size_t n); | ||||
| @ -34,8 +42,31 @@ char	*ft_strchr(const char *s, int c); | ||||
| char	*ft_strrchr(const char *s, int c); | ||||
| int		ft_strncmp(const char *s1, const char *s2, size_t n); | ||||
| void	*ft_memchr(const void *s, int c, size_t n); | ||||
| int		ft_memcmp(const void *s1, const void *s2, size_t n); | ||||
| void	*ft_memrchr(const void *s, int c, size_t n); | ||||
| char	*ft_strnstr(const char *big, const char *little, size_t len); | ||||
| int		ft_atoi(const char *nptr); | ||||
|  | ||||
| char	*ft_substr(const char *s, unsigned int start, size_t len); | ||||
| char	*ft_strjoin(const char *s1, const char *s2); | ||||
| char	*ft_strtrim(const char *s1, const char *set); | ||||
| char	*ft_itoa(int n); | ||||
| char	**ft_split(const char *s, char c); | ||||
| char	*ft_strmapi(const char *s, char (*f)(unsigned int, char)); | ||||
| void	ft_striteri(char *s, void (*f)(unsigned int, char*)); | ||||
| void	ft_putchar_fd(char c, int fd); | ||||
| void	ft_putstr_fd(char *s, int f); | ||||
| void	ft_putendl_fd(char *s, int fd); | ||||
| void	ft_putnbr_fd(int n, int fd); | ||||
|  | ||||
| t_list	*ft_lstnew(void *content); | ||||
| void	ft_lstadd_front(t_list **lst, t_list *new); | ||||
| int		ft_lstsize(t_list *lst); | ||||
| t_list	*ft_lstlast(t_list *lst); | ||||
| void	ft_lstadd_back(t_list **lst, t_list *new); | ||||
| void	ft_lstdelone(t_list *lst, void (*del)(void *)); | ||||
| void	ft_lstclear(t_list **lst, void (*del)(void *)); | ||||
| void	ft_lstiter(t_list *lst, void (*f)(void *)); | ||||
| t_list	*ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)); | ||||
|  | ||||
| #endif | ||||
|  | ||||
							
								
								
									
										30
									
								
								main.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								main.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | ||||
| /* ************************************************************************** */ | ||||
| /*                                                                            */ | ||||
| /*                                                        :::      ::::::::   */ | ||||
| /*   main.c                                             :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2022/10/04 13:56:50 by cchauvet          #+#    #+#             */ | ||||
| /*   Updated: 2022/10/04 13:57:56 by cchauvet         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
|  | ||||
| #include <stdio.h> | ||||
| #include "libft.h" | ||||
|  | ||||
| int	main(int argc, char **argv) | ||||
| { | ||||
| 	char	**splitted; | ||||
|  | ||||
| 	if (argc < 2) | ||||
| 		return (1); | ||||
| 	splitted = ft_split(argv[1], argv[2][0]); | ||||
| 	while (*splitted != NULL) | ||||
| 	{ | ||||
| 		puts(*splitted); | ||||
| 		free(*splitted); | ||||
| 		splitted++; | ||||
| 	} | ||||
| 	return (0); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user