From c87ab6728066ac2a752a3fdf2e5766f3da4afe1c Mon Sep 17 00:00:00 2001 From: Angel Ortigosa Perez Date: Sat, 15 Nov 2025 09:18:35 +0100 Subject: [PATCH] Libft aortigos --- Makefile | 36 +++++++++++++++ ft_atoi.c | 41 +++++++++++++++++ ft_bzero.c | 18 ++++++++ ft_calloc.c | 26 +++++++++++ ft_isalnum.c | 18 ++++++++ ft_isalpha.c | 18 ++++++++ ft_isascii.c | 18 ++++++++ ft_isdigit.c | 18 ++++++++ ft_isprint.c | 18 ++++++++ ft_itoa.c | 65 +++++++++++++++++++++++++++ ft_lstadd_back_bonus.c | 29 ++++++++++++ ft_lstadd_front_bonus.c | 21 +++++++++ ft_lstclear_bonus.c | 27 +++++++++++ ft_lstdelone_bonus.c | 24 ++++++++++ ft_lstiter_bonus.c | 24 ++++++++++ ft_lstlast_bonus.c | 26 +++++++++++ ft_lstmap_bonus.c | 38 ++++++++++++++++ ft_lstnew_bonus.c | 25 +++++++++++ ft_lstsize_bonus.c | 26 +++++++++++ ft_memchr.c | 29 ++++++++++++ ft_memcmp.c | 29 ++++++++++++ ft_memcpy.c | 30 +++++++++++++ ft_memmove.c | 42 +++++++++++++++++ ft_memset.c | 26 +++++++++++ ft_putchar_fd.c | 18 ++++++++ ft_putendl_fd.c | 26 +++++++++++ ft_putnbr_fd.c | 29 ++++++++++++ ft_putstr_fd.c | 25 +++++++++++ ft_split.c | 99 +++++++++++++++++++++++++++++++++++++++++ ft_strchr.c | 33 ++++++++++++++ ft_strdup.c | 29 ++++++++++++ ft_striteri.c | 27 +++++++++++ ft_strjoin.c | 40 +++++++++++++++++ ft_strlcat.c | 37 +++++++++++++++ ft_strlcpy.c | 34 ++++++++++++++ ft_strlen.c | 25 +++++++++++ ft_strmapi.c | 33 ++++++++++++++ ft_strncmp.c | 34 ++++++++++++++ ft_strnstr.c | 34 ++++++++++++++ ft_strrchr.c | 42 +++++++++++++++++ ft_strtrim.c | 37 +++++++++++++++ ft_substr.c | 41 +++++++++++++++++ ft_tolower.c | 22 +++++++++ ft_toupper.c | 22 +++++++++ libft.h | 80 +++++++++++++++++++++++++++++++++ 45 files changed, 1439 insertions(+) create mode 100644 Makefile create mode 100644 ft_atoi.c create mode 100644 ft_bzero.c create mode 100644 ft_calloc.c create mode 100644 ft_isalnum.c create mode 100644 ft_isalpha.c create mode 100644 ft_isascii.c create mode 100644 ft_isdigit.c create mode 100644 ft_isprint.c create mode 100644 ft_itoa.c create mode 100644 ft_lstadd_back_bonus.c create mode 100644 ft_lstadd_front_bonus.c create mode 100644 ft_lstclear_bonus.c create mode 100644 ft_lstdelone_bonus.c create mode 100644 ft_lstiter_bonus.c create mode 100644 ft_lstlast_bonus.c create mode 100644 ft_lstmap_bonus.c create mode 100644 ft_lstnew_bonus.c create mode 100644 ft_lstsize_bonus.c create mode 100644 ft_memchr.c create mode 100644 ft_memcmp.c create mode 100644 ft_memcpy.c create mode 100644 ft_memmove.c create mode 100644 ft_memset.c create mode 100644 ft_putchar_fd.c create mode 100644 ft_putendl_fd.c create mode 100644 ft_putnbr_fd.c create mode 100644 ft_putstr_fd.c create mode 100644 ft_split.c create mode 100644 ft_strchr.c create mode 100644 ft_strdup.c create mode 100644 ft_striteri.c create mode 100644 ft_strjoin.c create mode 100644 ft_strlcat.c create mode 100644 ft_strlcpy.c create mode 100644 ft_strlen.c create mode 100644 ft_strmapi.c create mode 100644 ft_strncmp.c create mode 100644 ft_strnstr.c create mode 100644 ft_strrchr.c create mode 100644 ft_strtrim.c create mode 100644 ft_substr.c create mode 100644 ft_tolower.c create mode 100644 ft_toupper.c create mode 100644 libft.h diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..42e15a2 --- /dev/null +++ b/Makefile @@ -0,0 +1,36 @@ +NAME = libft.a + +SRC = ft_strlen.c ft_strlcpy.c ft_strlcat.c ft_strchr.c ft_strrchr.c ft_strnstr.c ft_memset.c ft_memcpy.c ft_memmove.c ft_memchr.c ft_memcmp.c ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c ft_tolower.c ft_toupper.c ft_strncmp.c ft_atoi.c ft_bzero.c ft_calloc.c ft_strdup.c ft_substr.c ft_strjoin.c ft_strtrim.c ft_split.c ft_itoa.c ft_strmapi.c ft_striteri.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c + +SRC_B = ft_lstnew_bonus.c ft_lstadd_front_bonus.c ft_lstsize_bonus.c ft_lstlast_bonus.c ft_lstadd_back_bonus.c ft_lstdelone_bonus.c ft_lstclear_bonus.c ft_lstiter_bonus.c ft_lstmap_bonus.c + +OBJ = $(SRC:.c=.o) + +OBJS_B = ${SRC_B:.c=.o} + +CC = cc + +CFLAGS = -Wall -Wextra -Werror + +all: $(NAME) + +$(NAME): $(OBJ) + ar rc $(NAME) $(OBJ) + ranlib $(NAME) + +bonus: $(OBJ) $(OBJS_B) + ar rc $(NAME) $(OBJ) $(OBJS_B) + ranlib $(NAME) + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJ) $(OBJS_B) + +fclean: clean + rm -f $(NAME) + +re: fclean bonus + +.PHONY: bonus all clean fclean re diff --git a/ft_atoi.c b/ft_atoi.c new file mode 100644 index 0000000..ed4fe4c --- /dev/null +++ b/ft_atoi.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/22 20:46:43 by aortigos #+# #+# */ +/* Updated: 2023/10/18 20:41:03 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_atoi(const char *str) +{ + int sign; + int result; + int i; + + sign = 1; + result = 0; + i = 0; + while ((str[i] == ' ' || str[i] == '\t' || str[i] == '\n') + || (str[i] == '\v' || str[i] == '\r' || str[i] == '\f')) + i++; + if (str[i] == '-') + { + sign = -1; + } + if (str[i] == '-' || str[i] == '+') + { + i++; + } + while (str[i] >= '0' && str[i] <= '9') + { + result = result * 10 + (str[i] - '0'); + i++; + } + return (sign * result); +} diff --git a/ft_bzero.c b/ft_bzero.c new file mode 100644 index 0000000..f752fee --- /dev/null +++ b/ft_bzero.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/12 15:17:03 by aortigos #+# #+# */ +/* Updated: 2023/10/12 15:22:29 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_bzero(void *ptr, size_t num) +{ + ft_memset(ptr, 0, num); +} diff --git a/ft_calloc.c b/ft_calloc.c new file mode 100644 index 0000000..040a4d9 --- /dev/null +++ b/ft_calloc.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/24 15:16:49 by aortigos #+# #+# */ +/* Updated: 2023/09/24 15:18:05 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_calloc(size_t count, size_t size) +{ + void *ptr; + + ptr = malloc(count * size); + if (!(ptr)) + { + return (NULL); + } + ft_bzero(ptr, count * size); + return (ptr); +} diff --git a/ft_isalnum.c b/ft_isalnum.c new file mode 100644 index 0000000..22c9c44 --- /dev/null +++ b/ft_isalnum.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/20 17:52:29 by aortigos #+# #+# */ +/* Updated: 2023/10/26 07:40:16 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalnum(int c) +{ + return (ft_isdigit(c) || ft_isalpha(c)); +} diff --git a/ft_isalpha.c b/ft_isalpha.c new file mode 100644 index 0000000..5f9c53e --- /dev/null +++ b/ft_isalpha.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/19 18:25:08 by aortigos #+# #+# */ +/* Updated: 2023/10/26 07:39:20 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalpha(int c) +{ + return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')); +} diff --git a/ft_isascii.c b/ft_isascii.c new file mode 100644 index 0000000..9c4dc90 --- /dev/null +++ b/ft_isascii.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/20 17:55:43 by aortigos #+# #+# */ +/* Updated: 2023/10/26 07:39:27 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isascii(int c) +{ + return (c >= 0 && c <= 127); +} diff --git a/ft_isdigit.c b/ft_isdigit.c new file mode 100644 index 0000000..9813deb --- /dev/null +++ b/ft_isdigit.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/20 17:47:47 by aortigos #+# #+# */ +/* Updated: 2023/10/26 07:39:55 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isdigit(int c) +{ + return (c >= '0' && c <= '9'); +} diff --git a/ft_isprint.c b/ft_isprint.c new file mode 100644 index 0000000..487e9fc --- /dev/null +++ b/ft_isprint.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/20 17:57:36 by aortigos #+# #+# */ +/* Updated: 2023/10/26 07:39:39 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isprint(int c) +{ + return (c >= 32 && c <= 126); +} diff --git a/ft_itoa.c b/ft_itoa.c new file mode 100644 index 0000000..aa47366 --- /dev/null +++ b/ft_itoa.c @@ -0,0 +1,65 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/22 15:48:26 by aortigos #+# #+# */ +/* Updated: 2023/10/22 16:08:41 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static char *ft_array(char *x, unsigned int number, long int len) +{ + while (number > 0) + { + x[len--] = 48 + (number % 10); + number = number / 10; + } + return (x); +} + +static long int ft_len(int n) +{ + int len; + + len = 0; + if (n <= 0) + len = 1; + while (n != 0) + { + len++; + n = n / 10; + } + return (len); +} + +char *ft_itoa(int n) +{ + char *x; + long int len; + unsigned int number; + int sign; + + sign = 1; + len = ft_len(n); + x = (char *)malloc(sizeof(char) * (len + 1)); + if (!(x)) + return (NULL); + x[len--] = '\0'; + if (n == 0) + x[0] = '0'; + if (n < 0) + { + sign *= -1; + number = n * -1; + x[0] = '-'; + } + else + number = n; + x = ft_array(x, number, len); + return (x); +} diff --git a/ft_lstadd_back_bonus.c b/ft_lstadd_back_bonus.c new file mode 100644 index 0000000..58c0d20 --- /dev/null +++ b/ft_lstadd_back_bonus.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_back.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/22 20:27:06 by aortigos #+# #+# */ +/* Updated: 2023/10/22 20:37:18 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd_back(t_list **lst, t_list *new) +{ + t_list *i; + + if (lst) + { + if (*lst) + { + i = ft_lstlast(*lst); + i->next = new; + } + else + *lst = new; + } +} diff --git a/ft_lstadd_front_bonus.c b/ft_lstadd_front_bonus.c new file mode 100644 index 0000000..46a2dcc --- /dev/null +++ b/ft_lstadd_front_bonus.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_front.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/22 20:09:38 by aortigos #+# #+# */ +/* Updated: 2023/10/22 20:14:37 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd_front(t_list **lst, t_list *new) +{ + if (!new || !lst) + return ; + new->next = *lst; + *lst = new; +} diff --git a/ft_lstclear_bonus.c b/ft_lstclear_bonus.c new file mode 100644 index 0000000..504cae2 --- /dev/null +++ b/ft_lstclear_bonus.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstclear.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/23 16:28:57 by aortigos #+# #+# */ +/* Updated: 2023/10/23 17:30:44 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstclear(t_list **lst, void (*del)(void*)) +{ + t_list *tmp; + + if (!del || !lst || !*lst) + return ; + while (lst && *lst) + { + tmp = (*lst)->next; + ft_lstdelone(*lst, del); + *lst = tmp; + } +} diff --git a/ft_lstdelone_bonus.c b/ft_lstdelone_bonus.c new file mode 100644 index 0000000..4bafd03 --- /dev/null +++ b/ft_lstdelone_bonus.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/22 20:40:10 by aortigos #+# #+# */ +/* Updated: 2023/10/23 16:25:03 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstdelone(t_list *lst, void (*del)(void *)) +{ + if (!del) + return ; + if (lst) + { + (*del)(lst->content); + free(lst); + } +} diff --git a/ft_lstiter_bonus.c b/ft_lstiter_bonus.c new file mode 100644 index 0000000..9715a12 --- /dev/null +++ b/ft_lstiter_bonus.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstiter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/23 17:19:33 by aortigos #+# #+# */ +/* Updated: 2023/10/23 17:21:49 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstiter(t_list *lst, void (*f)(void*)) +{ + if (!f) + return ; + while (lst) + { + (*f)(lst->content); + lst = lst->next; + } +} diff --git a/ft_lstlast_bonus.c b/ft_lstlast_bonus.c new file mode 100644 index 0000000..3090946 --- /dev/null +++ b/ft_lstlast_bonus.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstlast.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/22 20:25:15 by aortigos #+# #+# */ +/* Updated: 2023/10/22 20:37:37 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstlast(t_list *lst) +{ + if (!lst) + return (NULL); + while (lst) + { + if (!lst->next) + return (lst); + lst = lst->next; + } + return (lst); +} diff --git a/ft_lstmap_bonus.c b/ft_lstmap_bonus.c new file mode 100644 index 0000000..bed74d0 --- /dev/null +++ b/ft_lstmap_bonus.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/23 17:25:38 by aortigos #+# #+# */ +/* Updated: 2023/10/24 18:15:50 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstmap(t_list *lst, void *(f)(void *), void (*del)(void *)) +{ + t_list *x; + t_list *new; + void *set; + + if (!lst || !f || !del) + return (NULL); + x = NULL; + while (lst) + { + set = f(lst->content); + new = ft_lstnew(set); + if (!new) + { + del(set); + ft_lstclear(&x, del); + return (NULL); + } + ft_lstadd_back(&x, new); + lst = lst->next; + } + return (x); +} diff --git a/ft_lstnew_bonus.c b/ft_lstnew_bonus.c new file mode 100644 index 0000000..4db040e --- /dev/null +++ b/ft_lstnew_bonus.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/22 20:07:04 by aortigos #+# #+# */ +/* Updated: 2023/10/22 20:08:16 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstnew(void *content) +{ + t_list *x; + + x = malloc(sizeof(t_list)); + if (!(x)) + return (NULL); + x->content = content; + x->next = NULL; + return (x); +} diff --git a/ft_lstsize_bonus.c b/ft_lstsize_bonus.c new file mode 100644 index 0000000..73a13f3 --- /dev/null +++ b/ft_lstsize_bonus.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstsize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/22 20:23:20 by aortigos #+# #+# */ +/* Updated: 2023/10/22 20:37:47 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_lstsize(t_list *lst) +{ + int i; + + i = 0; + while (lst) + { + lst = lst->next; + i++; + } + return (i); +} diff --git a/ft_memchr.c b/ft_memchr.c new file mode 100644 index 0000000..a463003 --- /dev/null +++ b/ft_memchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/22 19:00:54 by aortigos #+# #+# */ +/* Updated: 2023/10/26 07:41:42 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memchr(const void *s, int c, size_t n) +{ + size_t i; + + i = 0; + while (i < n) + { + if (((const unsigned char *)s)[i] == (unsigned char)c) + { + return ((void *)&((const unsigned char *)s)[i]); + } + i++; + } + return (NULL); +} diff --git a/ft_memcmp.c b/ft_memcmp.c new file mode 100644 index 0000000..2f7c4c0 --- /dev/null +++ b/ft_memcmp.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/22 19:17:43 by aortigos #+# #+# */ +/* Updated: 2023/09/22 19:21:07 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + unsigned int i; + + i = 0; + while (i < n) + { + if (((unsigned char *)s1)[i] != ((unsigned char *)s2)[i]) + { + return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]); + } + i++; + } + return (0); +} diff --git a/ft_memcpy.c b/ft_memcpy.c new file mode 100644 index 0000000..66f1e93 --- /dev/null +++ b/ft_memcpy.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/20 21:19:41 by aortigos #+# #+# */ +/* Updated: 2023/10/18 20:18:28 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memcpy(void *dst, const void *src, size_t num) +{ + size_t i; + + i = 0; + if (num == 0 || dst == src) + { + return (dst); + } + while (i < num) + { + ((char *)dst)[i] = ((char *)src)[i]; + i++; + } + return (dst); +} diff --git a/ft_memmove.c b/ft_memmove.c new file mode 100644 index 0000000..2f1795f --- /dev/null +++ b/ft_memmove.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/20 21:18:07 by aortigos #+# #+# */ +/* Updated: 2023/09/20 21:18:58 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memmove(void *dst, const void *src, size_t num) +{ + unsigned char *x; + const unsigned char *y; + + x = ((unsigned char *)dst); + y = ((const unsigned char *)src); + if (x != y) + { + if (x > y) + { + y = y + num - 1; + x = x + num - 1; + while (num > 0) + { + *x = *y; + x--; + y--; + num--; + } + } + else + { + dst = ft_memcpy(x, y, num); + } + } + return (dst); +} diff --git a/ft_memset.c b/ft_memset.c new file mode 100644 index 0000000..ab0146c --- /dev/null +++ b/ft_memset.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/20 18:12:08 by aortigos #+# #+# */ +/* Updated: 2023/10/08 16:36:16 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memset(void *ptr, int value, size_t num) +{ + size_t i; + + i = 0; + while (i < num) + { + ((char *)ptr)[i] = (unsigned char)value; + i++; + } + return (ptr); +} diff --git a/ft_putchar_fd.c b/ft_putchar_fd.c new file mode 100644 index 0000000..681b551 --- /dev/null +++ b/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/22 19:14:55 by aortigos #+# #+# */ +/* Updated: 2023/10/22 19:44:11 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/ft_putendl_fd.c b/ft_putendl_fd.c new file mode 100644 index 0000000..c6014c9 --- /dev/null +++ b/ft_putendl_fd.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/22 19:26:52 by aortigos #+# #+# */ +/* Updated: 2023/10/22 19:41:22 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putendl_fd(char *s, int fd) +{ + int i; + + i = 0; + while (s[i]) + { + write(fd, &s[i], 1); + i++; + } + write(fd, "\n", 1); +} diff --git a/ft_putnbr_fd.c b/ft_putnbr_fd.c new file mode 100644 index 0000000..110f636 --- /dev/null +++ b/ft_putnbr_fd.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/22 19:29:35 by aortigos #+# #+# */ +/* Updated: 2023/10/22 19:35:33 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putnbr_fd(int n, int fd) +{ + unsigned int nbr; + + if (n < 0) + { + ft_putchar_fd('-', fd); + nbr = (unsigned int)(n * -1); + } + else + nbr = (unsigned int)n; + if (nbr >= 10) + ft_putnbr_fd(nbr / 10, fd); + ft_putchar_fd((char)(nbr % 10 + 48), fd); +} diff --git a/ft_putstr_fd.c b/ft_putstr_fd.c new file mode 100644 index 0000000..3660d14 --- /dev/null +++ b/ft_putstr_fd.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/22 19:17:32 by aortigos #+# #+# */ +/* Updated: 2023/10/22 19:23:17 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putstr_fd(char *s, int fd) +{ + int i; + + i = 0; + while (s[i]) + { + write(fd, &s[i], 1); + i++; + } +} diff --git a/ft_split.c b/ft_split.c new file mode 100644 index 0000000..bb6c096 --- /dev/null +++ b/ft_split.c @@ -0,0 +1,99 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/22 10:43:43 by aortigos #+# #+# */ +/* Updated: 2023/10/22 10:56:39 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int count_str(char const *s1, char c) +{ + int i; + int j; + + i = 0; + j = 0; + if (*s1 == '\0') + return (0); + while (*s1 != '\0') + { + if (*s1 == c) + j = 0; + else if (j == 0) + { + j = 1; + i++; + } + s1++; + } + return (i); +} + +static int count_char(char const *s2, char c, int i) +{ + int len; + + len = 0; + while (s2[i] != c && s2[i] != '\0') + { + len++; + i++; + } + return (len); +} + +static char **free_mem(char const **dest, int j) +{ + while (j > 0) + { + j--; + free((void *)dest[j]); + } + free(dest); + return (NULL); +} + +static char **split(char const *s, char **dest, char c, int l) +{ + int i; + int j; + int k; + + i = 0; + j = 0; + while (s[i] != '\0' && j < l) + { + k = 0; + while (s[i] == c) + i++; + dest[j] = (char *)malloc(sizeof(char) * count_char(s, c, i) + 1); + if (dest[j] == NULL) + return (free_mem((char const **)dest, j)); + while (s[i] != '\0' && s[i] != c) + dest[j][k++] = s[i++]; + dest[j][k] = '\0'; + j++; + } + dest[j] = 0; + return (dest); +} + +char **ft_split(char const *s, char c) +{ + char **dest; + int i; + + if (s == NULL) + return (NULL); + i = count_str(s, c); + dest = (char **)malloc(sizeof(char *) * (i + 1)); + if (dest == NULL) + return (NULL); + return (split(s, dest, c, i)); +} diff --git a/ft_strchr.c b/ft_strchr.c new file mode 100644 index 0000000..ebb2f94 --- /dev/null +++ b/ft_strchr.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/21 17:16:15 by aortigos #+# #+# */ +/* Updated: 2023/10/12 15:15:10 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strchr(const char *str, int c) +{ + size_t i; + + i = 0; + while (str[i] != '\0') + { + if (str[i] == (char)c) + { + return ((char *)&str[i]); + } + i++; + } + if ((char)c == '\0') + { + return ((char *)&str[i]); + } + return (NULL); +} diff --git a/ft_strdup.c b/ft_strdup.c new file mode 100644 index 0000000..78dc3c7 --- /dev/null +++ b/ft_strdup.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/27 21:04:50 by aortigos #+# #+# */ +/* Updated: 2023/10/22 11:15:45 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strdup(const char *s1) +{ + char *s2; + size_t i; + + i = ft_strlen(s1); + s2 = (char *)malloc(i + 1); + if (!(s2)) + { + return (NULL); + } + ft_memcpy(s2, s1, i); + s2[i] = '\0'; + return (s2); +} diff --git a/ft_striteri.c b/ft_striteri.c new file mode 100644 index 0000000..71f54b2 --- /dev/null +++ b/ft_striteri.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/22 19:10:23 by aortigos #+# #+# */ +/* Updated: 2023/10/22 19:13:30 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_striteri(char *s, void (*f)(unsigned int, char *)) +{ + unsigned int i; + + if (!s || !(*s) || !f) + return ; + i = 0; + while (s[i]) + { + f(i, &s[i]); + i++; + } +} diff --git a/ft_strjoin.c b/ft_strjoin.c new file mode 100644 index 0000000..d9e249f --- /dev/null +++ b/ft_strjoin.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 19:39:00 by aortigos #+# #+# */ +/* Updated: 2023/10/03 19:47:34 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strjoin(char const *s1, char const *s2) +{ + char *x; + size_t c1; + size_t c2; + size_t i; + + i = 0; + c1 = 0; + c2 = 0; + if (s1 == NULL || s2 == NULL) + return (NULL); + x = (char *)malloc(sizeof(char) * ft_strlen(s1) + ft_strlen(s2) + 1); + if (!(x)) + return (NULL); + while (c1 != ft_strlen(s1)) + { + x[i++] = s1[c1++]; + } + while (c2 != ft_strlen(s2)) + { + x[i++] = s2[c2++]; + } + x[i] = '\0'; + return (x); +} diff --git a/ft_strlcat.c b/ft_strlcat.c new file mode 100644 index 0000000..bf2ad0d --- /dev/null +++ b/ft_strlcat.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/20 21:30:13 by aortigos #+# #+# */ +/* Updated: 2023/09/22 18:35:30 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcat(char *dest, const char *src, size_t size) +{ + size_t i; + size_t len; + + len = 0; + i = 0; + while (dest[i] != '\0' && i < size) + { + i++; + } + len = i; + while (src[i - len] && i + 1 < size) + { + dest[i] = src[i - len]; + i++; + } + if (i < size) + { + dest[i] = '\0'; + } + return (len + ft_strlen(src)); +} diff --git a/ft_strlcpy.c b/ft_strlcpy.c new file mode 100644 index 0000000..3bd8e08 --- /dev/null +++ b/ft_strlcpy.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/20 21:20:19 by aortigos #+# #+# */ +/* Updated: 2023/10/22 15:42:47 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcpy(char *dest, const char *src, size_t size) +{ + size_t i; + + i = 0; + if (size > 0) + { + while (src[i] && i < (size - 1)) + { + dest[i] = src[i]; + i++; + } + dest[i] = 0; + } + while (src[i]) + { + i++; + } + return (i); +} diff --git a/ft_strlen.c b/ft_strlen.c new file mode 100644 index 0000000..dab8352 --- /dev/null +++ b/ft_strlen.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/20 17:58:58 by aortigos #+# #+# */ +/* Updated: 2023/10/26 07:38:05 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlen(const char *str) +{ + size_t i; + + i = 0; + while (str[i] != '\0') + { + i++; + } + return (i); +} diff --git a/ft_strmapi.c b/ft_strmapi.c new file mode 100644 index 0000000..7a28b35 --- /dev/null +++ b/ft_strmapi.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/22 16:12:53 by aortigos #+# #+# */ +/* Updated: 2023/10/26 07:37:07 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f) (unsigned int, char)) +{ + char *x; + unsigned int i; + + i = 0; + if (!s) + return (NULL); + x = malloc(sizeof(char) * ft_strlen(s) + 1); + if (!(x)) + return (NULL); + while (i != ft_strlen(s)) + { + x[i] = (*f)(i, s[i]); + i++; + } + x[i] = '\0'; + return (x); +} diff --git a/ft_strncmp.c b/ft_strncmp.c new file mode 100644 index 0000000..3ba7006 --- /dev/null +++ b/ft_strncmp.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/22 18:50:00 by aortigos #+# #+# */ +/* Updated: 2023/10/26 07:36:41 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strncmp(const char *s1, const char *s2, size_t n) +{ + size_t i; + size_t re; + + i = 0; + re = 0; + if (n == 0) + return (0); + while (i < n && (s1[i] != '\0' && s1[i] == s2[i])) + { + i++; + } + if (i == n) + { + i--; + } + re = (unsigned char)s1[i] - (unsigned char)s2[i]; + return (re); +} diff --git a/ft_strnstr.c b/ft_strnstr.c new file mode 100644 index 0000000..fa04529 --- /dev/null +++ b/ft_strnstr.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/22 19:22:45 by aortigos #+# #+# */ +/* Updated: 2023/09/22 20:44:40 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strnstr(const char *haystack, const char *needle, size_t n) +{ + size_t c; + + if (*needle == '\0') + { + return ((char *)haystack); + } + c = ft_strlen(needle); + while (*haystack && c <= n) + { + if (ft_strncmp(haystack, needle, c) == 0) + { + return ((char *)haystack); + } + haystack++; + n--; + } + return (NULL); +} diff --git a/ft_strrchr.c b/ft_strrchr.c new file mode 100644 index 0000000..0d7bb2d --- /dev/null +++ b/ft_strrchr.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/22 18:34:08 by aortigos #+# #+# */ +/* Updated: 2023/10/19 16:15:09 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strrchr(const char *str, int c) +{ + char x; + size_t i; + + i = 0; + x = ((char)c); + while (str[i] != '\0') + { + i++; + } + while (i > 0) + { + if (str[i] == x) + { + return (&((char *)str)[i]); + } + i--; + } + if (i == 0) + { + if (str[i] == x) + { + return (&((char *)str)[i]); + } + } + return (0); +} diff --git a/ft_strtrim.c b/ft_strtrim.c new file mode 100644 index 0000000..dc373dc --- /dev/null +++ b/ft_strtrim.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 20:21:56 by aortigos #+# #+# */ +/* Updated: 2023/10/19 16:58:30 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strtrim(char const *s1, char const *set) +{ + size_t len; + char *x; + + if (!s1 || !set) + return (NULL); + while (ft_strchr(set, *s1) && *s1 != '\0') + { + s1++; + } + if (*s1 == '\0') + { + return (ft_strdup("")); + } + len = ft_strlen(s1); + while (ft_strchr(set, s1[len])) + { + len--; + } + x = ft_substr(s1, 0, len + 1); + return (x); +} diff --git a/ft_substr.c b/ft_substr.c new file mode 100644 index 0000000..e112c24 --- /dev/null +++ b/ft_substr.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/24 15:15:06 by aortigos #+# #+# */ +/* Updated: 2023/10/23 18:29:42 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + char *x; + size_t i; + + if (!s) + return (NULL); + if (ft_strlen(s) < start) + { + x = ft_calloc(1, sizeof(char)); + if (!x) + return (NULL); + } + else + { + i = ft_strlen(s + start); + if (!(i < len)) + i = len; + x = (char *)malloc((i + 1) * sizeof(char)); + if (!x) + return (NULL); + x[i] = 0; + while (i-- > 0) + x[i] = s[start + i]; + } + return (x); +} diff --git a/ft_tolower.c b/ft_tolower.c new file mode 100644 index 0000000..94610d2 --- /dev/null +++ b/ft_tolower.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/21 17:13:25 by aortigos #+# #+# */ +/* Updated: 2023/09/22 18:45:54 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + { + return (c + 32); + } + return (c); +} diff --git a/ft_toupper.c b/ft_toupper.c new file mode 100644 index 0000000..e53d652 --- /dev/null +++ b/ft_toupper.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/21 16:40:59 by aortigos #+# #+# */ +/* Updated: 2023/10/04 20:20:28 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_toupper(int c) +{ + if (c >= 'a' && c <= 'z') + { + return (c - 32); + } + return (c); +} diff --git a/libft.h b/libft.h new file mode 100644 index 0000000..da11c1d --- /dev/null +++ b/libft.h @@ -0,0 +1,80 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/22 20:56:18 by aortigos #+# #+# */ +/* Updated: 2023/10/26 07:37:33 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +# include +# include +# include +# include +# include + +typedef struct s_list +{ + void *content; + struct s_list *next; +} t_list; + +// String + +size_t ft_strlen(const char *str); +size_t ft_strlcpy(char *dest, const char *src, size_t size); +size_t ft_strlcat(char *dest, const char *src, size_t size); +char *ft_strchr(const char *str, int c); +char *ft_strrchr(const char *str, int c); +char *ft_strnstr(const char *haystack, const char *needle, size_t n); +char *ft_strdup(const char *s1); +char *ft_substr(char const *s, unsigned int start, size_t len); +char *ft_strjoin(char const *s1, char const *s2); +char *ft_strtrim(char const *s1, char const *set); +char **ft_split(char const *s, char c); +char *ft_itoa(int n); +char *ft_strmapi(char const *s, char (*f) (unsigned int, char)); + +// Memoria +void *ft_memset(void *ptr, int value, size_t num); +void *ft_memcpy(void *dst, const void *src, size_t num); +void *ft_memmove(void *dst, const void *src, size_t num); +void *ft_memchr(const void *s, int c, size_t n); +void *ft_calloc(size_t count, size_t size); +void ft_bzero(void *ptr, size_t num); +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 fd); +void ft_putendl_fd(char *s, int fd); +void ft_putnbr_fd(int n, int fd); +int ft_memcmp(const void *s1, const void *s2, size_t n); + +// Caracteres +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); +int ft_tolower(int c); +int ft_toupper(int c); + +// Otras funciones +int ft_strncmp(const char *s1, const char *s2, size_t n); +int ft_atoi(const char *str); + +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