diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..aea151c --- /dev/null +++ b/Makefile @@ -0,0 +1,85 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: mcombeau +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2021/11/22 13:48:30 by mcombeau #+# #+# # +# Updated: 2021/12/02 13:26:19 by mcombeau ### ########.fr # +# # +# **************************************************************************** # + +NAME = libft.a +CC = gcc +CFLAGS = -Wall -Werror -Wextra -g3 +AR = ar rcs +SRC = ft_isalpha \ + ft_isdigit \ + ft_isalnum \ + ft_isascii \ + ft_isprint \ + ft_strlen \ + ft_memset \ + ft_bzero \ + ft_memcpy \ + ft_memmove \ + ft_strlcpy \ + ft_strlcat \ + ft_toupper \ + ft_tolower \ + ft_strchr \ + ft_strrchr \ + ft_strncmp \ + ft_memchr \ + ft_memcmp \ + ft_strnstr \ + ft_atoi \ + ft_calloc \ + ft_strdup \ + ft_substr \ + ft_strjoin \ + ft_strtrim \ + ft_split \ + ft_itoa \ + ft_strmapi \ + ft_striteri \ + ft_putchar_fd \ + ft_putstr_fd \ + ft_putendl_fd \ + ft_putnbr_fd +BONUS_SRC = ft_lstnew \ + ft_lstadd_front \ + ft_lstsize \ + ft_lstlast \ + ft_lstadd_back \ + ft_lstdelone \ + ft_lstclear \ + ft_lstiter \ + ft_lstmap + +SRCS = $(addsuffix .c, $(SRC)) +OBJS = $(addsuffix .o, $(SRC)) +BONUS_SRCS = $(addsuffix .c, $(BONUS_SRC)) +BONUS_OBJS = $(addsuffix .o, $(BONUS_SRC)) + +.c.o: $(SRCS) $(BONUS_SRCS) + $(CC) $(CFLAGS) -c -o $@ $< + +$(NAME): $(OBJS) + $(AR) $@ $^ + +bonus: $(OBJS) $(BONUS_OBJS) + $(AR) $(NAME) $^ + +all: $(NAME) + +clean: + rm -f *.o + +fclean: clean + rm -f $(NAME) + +re: clean all + +.PHONY: all clean fclean re bonus diff --git a/README.md b/README.md new file mode 100644 index 0000000..edb5170 --- /dev/null +++ b/README.md @@ -0,0 +1,79 @@ +# libft +42 school's first project, libft, is about learning how the standard functions of C programming work, by coding them from scratch and creating our very own library. + +Libft is a very important project, since this library will be used in future 42 school assignments. If you are a 42 student, I highly recommend you go through the trial and error process of writing your own code and testing it yourself, rather than copy-pasting code you only half-understand. If you've succeeded your piscine, there is no reason you couldn't figure this project out for yourself! Be patient and thorough. + +## Status +2022-01-18: Finished. + +[![jaeskim's 42Project Score](https://badge42.herokuapp.com/api/project/mcombeau/Libft)](https://github.com/JaeSeoKim/badge42) + +## Usage +``make`` to compile mandatory functions. + +``make bonus`` to compile with bonus functions. + +## Included Functions + +### Mandatory Functions +The mandatory functions of libft are either functions from the standard C library or other useful functions. They are mostly useful for character, string and memory manipulation. These 34 mandatory functions must be done correctly to get a 100% grade. + +Functions to check and manipulate characters: +- ft_isalpha +- ft_isdigit +- ft_isalnum +- ft_isascii +- ft_isprint +- ft_toupper +- ft_tolower + +Functions to manipulate strings: +- ft_strlen +- ft_strlcpy +- ft_strlcat +- ft_strchr +- ft_strrchr +- ft_strncmp +- ft_strnstr +- ft_substr +- ft_strjoin +- ft_strtrim +- ft_split +- ft_strmapi +- ft_striteri + +Functions to manipulate memory: +- ft_calloc +- ft_memset +- ft_bzero +- ft_memcpy +- ft_memmove +- ft_memchr +- ft_memcmp +- ft_strdup + +Functions for numbers: +- ft_atoi +- ft_itoa + +Functions to write to a file descriptor +- ft_putchar_fd +- ft_putstr_fd +- ft_putendl_fd +- ft_putnbr_fd + +### Bonus Functions +The bonus functions of libft deal with list manipulation. This part is worth an extra 25% to the final grade. +- ft_lstnew +- ft_lstadd_front +- ft_lstsize +- ft_lstlast +- ft_lstadd_back +- ft_lstdelone +- ft_lstclear +- ft_lstiter +- ft_lstmap + + +--- +Made by mcombeau: mcombeau@student.42.fr | LinkedIn: [mcombeau](https://www.linkedin.com/in/mia-combeau-86653420b/) | Website: [codequoi.com](https://www.codequoi.com) diff --git a/ft_atoi.c b/ft_atoi.c new file mode 100644 index 0000000..92af683 --- /dev/null +++ b/ft_atoi.c @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/24 18:06:58 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 16:48:58 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_atoi converts a string into an int. + + RETURN VALUE : + The converted int. +*/ + +int ft_atoi(const char *str) +{ + int num; + int isneg; + int i; + + num = 0; + isneg = 1; + i = 0; + while (str[i] && (str[i] == ' ' || str[i] == '\t' + || str[i] == '\n' || str[i] == '\r' + || str[i] == '\v' || str[i] == '\f')) + i++; + if (str[i] == '+') + i++; + else if (str[i] == '-') + { + isneg *= -1; + i++; + } + while (ft_isdigit(str[i])) + { + num = (num * 10) + (str[i] - '0'); + i++; + } + return (num * isneg); +} diff --git a/ft_bzero.c b/ft_bzero.c new file mode 100644 index 0000000..cad5fa2 --- /dev/null +++ b/ft_bzero.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/23 14:22:49 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 14:21:37 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_bzero erases data in the n bytes of memory starting + at location s by writing '\0's. + + RETURN VALUE : + None. +*/ + +void ft_bzero(void *s, size_t n) +{ + unsigned char *p; + + p = (unsigned char *)s; + while (n != 0) + { + *p = '\0'; + p++; + n--; + } +} diff --git a/ft_calloc.c b/ft_calloc.c new file mode 100644 index 0000000..c68d81c --- /dev/null +++ b/ft_calloc.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/26 15:28:22 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 16:49:19 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_calloc allocates memory for an array of count elements + of size bytes each and sets the memory to zero. + + RETURN VALUE : + The pointer to the allocated memory. NULL if the memory allocation fails. +*/ + +void *ft_calloc(size_t count, size_t size) +{ + void *r; + + r = malloc(count * size); + if (!r) + return (NULL); + ft_bzero(r, size * count); + return (r); +} diff --git a/ft_isalnum.c b/ft_isalnum.c new file mode 100644 index 0000000..64329a9 --- /dev/null +++ b/ft_isalnum.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/22 13:52:40 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 16:49:56 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_isalnum checks whether the value of c is alphanumeric. + + RETURN VALUE : + Non-zero if c is alphanumeric, zero if not. +*/ + +int ft_isalnum(int c) +{ + if (ft_isalpha(c) || ft_isdigit(c)) + return (c); + return (0); +} diff --git a/ft_isalpha.c b/ft_isalpha.c new file mode 100644 index 0000000..71ec9c3 --- /dev/null +++ b/ft_isalpha.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/22 13:50:28 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 14:36:38 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* + DESCRIPTION : + The function ft_isalpha checks whether c is alphabetic or not. + + RETURN VALUE : + Non-zero if c is alphabetic, zero if not. +*/ + +int ft_isalpha(int c) +{ + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) + return (c); + return (0); +} diff --git a/ft_isascii.c b/ft_isascii.c new file mode 100644 index 0000000..ad8dcea --- /dev/null +++ b/ft_isascii.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/22 13:48:51 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 14:38:16 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* + DESCRIPTION : + The function ft_isascii checks whether c is an ascii character or not. + + RESULT VALUE : + Non-zero if c is ascii, zero if not. +*/ + +int ft_isascii(int c) +{ + if (c == 0) + return (1); + if (c > 0 && c <= 127) + return (c); + return (0); +} diff --git a/ft_isdigit.c b/ft_isdigit.c new file mode 100644 index 0000000..42c2828 --- /dev/null +++ b/ft_isdigit.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/22 13:53:06 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 14:40:52 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* + DESCRIPTION : + The function ft_isdigit checks whether c is a digit character or not. + + RETURN VALUE: + Non-zero if c is a digit, zero if not. +*/ + +int ft_isdigit(int c) +{ + if (c >= '0' && c <= '9') + return (c); + return (0); +} diff --git a/ft_isprint.c b/ft_isprint.c new file mode 100644 index 0000000..6de36e3 --- /dev/null +++ b/ft_isprint.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/22 13:50:49 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 14:42:17 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* + DESCRIPTION : + The function ft_isprint checks whether c is a printable character or not. + + RETURN VALUE : + Non-zero if c is printable, zero if not. +*/ + +int ft_isprint(int c) +{ + if (c >= ' ' && c <= '~') + return (c); + return (0); +} diff --git a/ft_itoa.c b/ft_itoa.c new file mode 100644 index 0000000..84ae411 --- /dev/null +++ b/ft_itoa.c @@ -0,0 +1,78 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/27 18:04:16 by mcombeau #+# #+# */ +/* Updated: 2021/12/08 12:12:23 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_itoa converts the integer n into a string of characters. + + RESULT VALUE : + The string of the converted integer. +*/ + +static size_t ft_itoa_len(long num) +{ + size_t len; + + len = 0; + if (num == 0) + return (1); + if (num < 0) + { + len++; + num = -num; + } + while (num >= 1) + { + len++; + num /= 10; + } + return (len); +} + +static char *ft_num_to_str(long num, char *str, size_t len) +{ + str = ft_calloc(len + 1, sizeof(char)); + if (str == NULL) + return (NULL); + if (num < 0) + { + str[0] = '-'; + num = -num; + } + len--; + while (len) + { + str[len] = (num % 10) + '0'; + num /= 10; + len--; + } + if (str[0] != '-') + str[0] = (num % 10) + '0'; + return (str); +} + +char *ft_itoa(int n) +{ + long num; + size_t len; + char *str; + + num = n; + len = ft_itoa_len(num); + str = 0; + str = ft_num_to_str(num, str, len); + if (!str) + return (NULL); + return (str); +} diff --git a/ft_lstadd_back.c b/ft_lstadd_back.c new file mode 100644 index 0000000..c7e65c5 --- /dev/null +++ b/ft_lstadd_back.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_back.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/12/01 19:56:07 by mcombeau #+# #+# */ +/* Updated: 2021/12/08 12:22:04 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_lstadd_back adds a new node to the back of a list: + [.]->[.]->[.]->[NEW]->[NULL] + + RETURN VALUE : + None. +*/ + +void ft_lstadd_back(t_list **alst, t_list *new) +{ + t_list *tmp; + + if (!new) + return ; + if (!*alst) + { + *alst = new; + return ; + } + tmp = ft_lstlast(*alst); + tmp->next = new; +} diff --git a/ft_lstadd_front.c b/ft_lstadd_front.c new file mode 100644 index 0000000..aa79b1c --- /dev/null +++ b/ft_lstadd_front.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_front.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/30 22:10:05 by mcombeau #+# #+# */ +/* Updated: 2021/12/07 12:13:58 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_lstadd_front adds a new node to the front of a list: + [NEW]->[.]->[.]->[.]->[NULL] + + RETURN VALUE : + None. +*/ + +void ft_lstadd_front(t_list **alst, t_list *new) +{ + if (!new) + return ; + if (!*alst) + { + *alst = new; + return ; + } + new->next = *alst; + *alst = new; +} diff --git a/ft_lstclear.c b/ft_lstclear.c new file mode 100644 index 0000000..371ea75 --- /dev/null +++ b/ft_lstclear.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstclear.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/12/01 20:11:58 by mcombeau #+# #+# */ +/* Updated: 2021/12/05 13:09:17 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_lstclear deletes each node of a list with the function + passed as parameter. It also frees the memory of each node and finally + sets the list pointer to NULL. + + RETURN VALUE : + None. +*/ + +void ft_lstclear(t_list **lst, void (*del)(void *)) +{ + t_list *tmp; + + if (!lst) + return ; + while (*lst) + { + tmp = (*lst)->next; + ft_lstdelone(*lst, del); + *lst = tmp; + } + *lst = NULL; +} diff --git a/ft_lstdelone.c b/ft_lstdelone.c new file mode 100644 index 0000000..2cf2924 --- /dev/null +++ b/ft_lstdelone.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/12/01 20:05:57 by mcombeau #+# #+# */ +/* Updated: 2021/12/05 13:10:41 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_lstdelone deletes the content of a list node with the + function passed as parameter before freeing the memory of the node. + + RETURN VALUE : + None. +*/ + +void ft_lstdelone(t_list *lst, void (*del)(void *)) +{ + if (!lst) + return ; + if (del) + (del)(lst->content); + free(lst); +} diff --git a/ft_lstiter.c b/ft_lstiter.c new file mode 100644 index 0000000..e5bd6dd --- /dev/null +++ b/ft_lstiter.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstiter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/12/01 20:26:30 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 16:50:47 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_lstiter applies the function f passed as parameter + to the content of each node of a given list. + + RETURN VALUE : + None. +*/ + +void ft_lstiter(t_list *lst, void (*f)(void *)) +{ + if (!f || !lst) + return ; + while (lst) + { + f(lst->content); + lst = lst->next; + } +} diff --git a/ft_lstlast.c b/ft_lstlast.c new file mode 100644 index 0000000..43bee4c --- /dev/null +++ b/ft_lstlast.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstlast.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/12/01 19:48:52 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 16:51:11 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_lstlast finds the last node in a given list. + + RETURN VALUE : + The last node of a list. + [.]->[.]->[.]->[LAST]->[NULL] +*/ + +t_list *ft_lstlast(t_list *lst) +{ + if (!lst) + return (NULL); + while (lst != NULL && lst->next != NULL) + lst = lst->next; + return (lst); +} diff --git a/ft_lstmap.c b/ft_lstmap.c new file mode 100644 index 0000000..481ee3b --- /dev/null +++ b/ft_lstmap.c @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/12/01 20:34:19 by mcombeau #+# #+# */ +/* Updated: 2021/12/04 13:13:40 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_lstmap creates a new list from a given list by + applying the function passed as parameter to the original list. If + the memory allocation fails for any node in the new list, the new list + will be deleted with the function passed as parameter and its memory + will be freed. + + RETURN VALUE : + The new list containing the new values if a functon was provided. + A new copy of the list if no function was provided. + NULL if the memory allocation failed. +*/ + +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) +{ + t_list *newlst; + t_list *node; + + if (!lst) + return (NULL); + newlst = NULL; + node = NULL; + while (lst) + { + if (!f) + node = ft_lstnew(lst->content); + else + node = ft_lstnew(f(lst->content)); + if (!node) + { + ft_lstclear(&newlst, del); + return (NULL); + } + ft_lstadd_back(&newlst, node); + lst = lst->next; + } + return (newlst); +} diff --git a/ft_lstnew.c b/ft_lstnew.c new file mode 100644 index 0000000..62d3028 --- /dev/null +++ b/ft_lstnew.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/30 17:28:58 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 15:13:17 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_lstnew allocates memory for a new list node and + initializes its content to the value passed as parameter, before + setting its next node to NULL. + + RESULT VALUE : + The new list ode. +*/ + +t_list *ft_lstnew(void *content) +{ + t_list *list; + + list = malloc(sizeof(t_list)); + if (!list) + return (NULL); + list->content = content; + list->next = NULL; + return (list); +} diff --git a/ft_lstsize.c b/ft_lstsize.c new file mode 100644 index 0000000..7d8afb1 --- /dev/null +++ b/ft_lstsize.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstsize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/12/01 19:44:21 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 15:15:06 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_lstsize measures the size of a given list by counting + the number of nodes in it. + + RETURN VALUE : + The integer number of nodes in the given list. +*/ + +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..14950a1 --- /dev/null +++ b/ft_memchr.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/25 21:57:14 by mcombeau #+# #+# */ +/* Updated: 2021/12/03 16:31:15 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_memchr searches n bytes of the memory area pointed to + by s for the first occurence of c. Both c and the bytes of s are + interpreted as unsigned char. + + RETURN VALUE: + A pointer to the matching byte. NULL if the character does not occur + in the given memory area. +*/ + +void *ft_memchr(const void *s, int c, size_t n) +{ + size_t i; + unsigned char ch; + const unsigned char *str; + + ch = c; + str = (const unsigned char *)s; + i = 0; + while (i < n) + { + if (str[i] == ch) + return ((void *)s + i); + i++; + } + return (0); +} diff --git a/ft_memcmp.c b/ft_memcmp.c new file mode 100644 index 0000000..3300ba0 --- /dev/null +++ b/ft_memcmp.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/25 22:41:23 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 16:51:42 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_memcmp compares the first n bytes of the memory areas + s1 and s2. The bytes are interpreted as unsigned char. + + RETURN VALUE : + An integer less than, equal to, or greater than zero if the first + n bytes of s1 is found to be less than, equal to, or greater than the + first n bytes of s2. Zero if n is equal to zero. +*/ + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + const char *str1; + const char *str2; + size_t i; + + if (n == 0) + return (0); + str1 = (const char *)s1; + str2 = (const char *)s2; + i = 0; + while ((i < n - 1) && str1[i] == str2[i]) + i++; + return ((unsigned char)str1[i] - (unsigned char)str2[i]); +} diff --git a/ft_memcpy.c b/ft_memcpy.c new file mode 100644 index 0000000..8e80190 --- /dev/null +++ b/ft_memcpy.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/23 15:02:13 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 15:26:40 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_memcpy copies n bytes from memory area src to memory + area dst. + Does not account for memory overlaps. Use ft_memmove if the memory areas + overlap or might overlap. + + RETURN VALUE : + A pointer to dst. NULL if src and dst are both NULL. +*/ + +void *ft_memcpy(void *dst, const void *src, size_t n) +{ + char *dp; + const char *sp; + + if (!dst && !src) + return (0); + if (n == 0 || (dst == src)) + return (dst); + dp = (char *)dst; + sp = (const char *)src; + while (n != 0) + { + if (*dp != *sp) + *dp = *sp; + dp++; + sp++; + n--; + } + return (dst); +} diff --git a/ft_memmove.c b/ft_memmove.c new file mode 100644 index 0000000..239aa0b --- /dev/null +++ b/ft_memmove.c @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/23 15:57:19 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 16:48:38 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_memmove copies n bytes from memory area src to memory + area dst. The memory areas may overlap: if the dst pointer is found + to be between the src pointer and the index n, copying will be done + back to front to prevent data being modified before being copied. + Otherwise it will be done front to back to preserve data. + + RETURN VALUE : + A pointer to dst. +*/ + +void *ft_memmove(void *dst, const void *src, size_t len) +{ + char *dp; + const char *sp; + + if (src == dst) + return (dst); + dp = (char *)dst; + sp = (const char *)src; + if (sp < dp && sp + len > dp) + while (len--) + *(dp + len) = *(sp + len); + else + { + while (len--) + { + *dp = *sp; + sp++; + dp++; + } + } + return (dst); +} diff --git a/ft_memset.c b/ft_memset.c new file mode 100644 index 0000000..7d5436c --- /dev/null +++ b/ft_memset.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/22 13:48:14 by mcombeau #+# #+# */ +/* Updated: 2021/12/03 12:05:11 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_memset fills the first len bytes of the memory area + pointed to by b with the byte c. Both b and c are interpreted as + unsigned char. + + RETURN VALUE : + A pointer to memory area s. +*/ + +void *ft_memset(void *b, int c, size_t len) +{ + unsigned char *p; + unsigned char ch; + + p = (unsigned char *)b; + ch = c; + while (len--) + { + *p = ch; + p++; + } + return (b); +} diff --git a/ft_putchar_fd.c b/ft_putchar_fd.c new file mode 100644 index 0000000..41c2e47 --- /dev/null +++ b/ft_putchar_fd.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/28 05:38:33 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 15:40:12 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_putchar_fd writes the given character to the given + file descriptor. + + RETURN VALUE : + None. +*/ + +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..e51af73 --- /dev/null +++ b/ft_putendl_fd.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/28 06:13:20 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 15:41:38 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_putendl_fd writes the given string to the given + file descriptor followed by a new line. + + RETURN VALUE : + None. +*/ + +void ft_putendl_fd(char *s, int fd) +{ + ft_putstr_fd(s, fd); + ft_putchar_fd('\n', fd); +} diff --git a/ft_putnbr_fd.c b/ft_putnbr_fd.c new file mode 100644 index 0000000..6c7dcf3 --- /dev/null +++ b/ft_putnbr_fd.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/28 06:22:02 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 15:44:08 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_putnbr_fd writes the given integer n on the given + file descriptor by converting it into char. + + RETURN VALUE : + None. +*/ + +void ft_putnbr_fd(int n, int fd) +{ + long nbr; + + nbr = n; + if (nbr < 0) + { + ft_putchar_fd('-', fd); + nbr = -nbr; + } + if (nbr >= 10) + { + ft_putnbr_fd(nbr / 10, fd); + ft_putchar_fd((nbr % 10) + '0', fd); + } + else + ft_putchar_fd(nbr + '0', fd); +} diff --git a/ft_putstr_fd.c b/ft_putstr_fd.c new file mode 100644 index 0000000..7ade5d4 --- /dev/null +++ b/ft_putstr_fd.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/28 05:42:28 by mcombeau #+# #+# */ +/* Updated: 2021/12/03 16:23:10 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_putstr_fd writes the given string to the given + file descriptor. + + RETURN VALUE : + None. +*/ + +void ft_putstr_fd(char *s, int fd) +{ + if (!s) + return ; + while (*s != '\0') + { + ft_putchar_fd(*s, fd); + s++; + } +} diff --git a/ft_split.c b/ft_split.c new file mode 100644 index 0000000..eddbcaf --- /dev/null +++ b/ft_split.c @@ -0,0 +1,136 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/27 17:56:03 by mcombeau #+# #+# */ +/* Updated: 2021/12/08 12:14:01 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_split allocates and copies an array of strings by + splitting the given string s using the given separator c. + + RETURN VALUE : + An array of strings resulting from the split. NULL if the memory + allocation fails. +*/ + +static int ft_count_words(const char *s, char c) +{ + int words; + int i; + + words = 0; + i = 0; + while (s[i]) + { + if (i == 0 && s[i] != c) + words++; + if (i > 0 && s[i] != c && s[i - 1] == c) + words++; + i++; + } + return (words); +} + +static char **ft_malloc_strs(char **strs, const char *s, char c) +{ + int count; + int i; + int x; + + count = 0; + i = 0; + x = 0; + while (s[i]) + { + if (s[i] != c) + count++; + if ((s[i] == c && i > 0 && s[i - 1] != c) + || (s[i] != c && s[i + 1] == '\0')) + { + strs[x] = malloc(sizeof(char) * (count + 1)); + if (!strs[x]) + return (NULL); + count = 0; + x++; + } + i++; + } + return (strs); +} + +static char **ft_cpy_strs(char **strs, const char *s, char c) +{ + int i; + int x; + int y; + + i = 0; + x = 0; + y = 0; + while (s[i]) + { + if (s[i] != c) + strs[x][y++] = s[i]; + if (s[i] != c && s[i + 1] == '\0') + strs[x][y] = '\0'; + if (s[i] == c && i > 0 && s[i - 1] != c) + { + strs[x][y] = '\0'; + x++; + y = 0; + } + i++; + } + return (strs); +} + +static char **ft_merror(char **strs) +{ + int i; + + i = 0; + while (strs[i]) + { + free(strs[i]); + strs[i] = NULL; + i++; + } + free(strs); + return (NULL); +} + +char **ft_split(char const *s, char c) +{ + char **strs; + int wordcount; + + if (!s) + { + strs = malloc(sizeof(char) * 1); + if (!strs) + return (NULL); + *strs = NULL; + return (strs); + } + wordcount = ft_count_words(s, c); + strs = malloc(sizeof(*strs) * (wordcount + 1)); + if (!strs) + return (NULL); + if (ft_malloc_strs(strs, s, c)) + { + ft_cpy_strs(strs, s, c); + strs[wordcount] = NULL; + } + else + strs = ft_merror(strs); + return (strs); +} diff --git a/ft_strchr.c b/ft_strchr.c new file mode 100644 index 0000000..c26c114 --- /dev/null +++ b/ft_strchr.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/22 13:53:33 by mcombeau #+# #+# */ +/* Updated: 2021/12/05 15:35:48 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_strchr finds the first occurence of character c in + string str. + + RETURN VALUE : + A pointer to the first occurence of c in str. + NULL if c is not found. +*/ + +char *ft_strchr(const char *str, int c) +{ + int i; + unsigned char ch; + + i = 0; + ch = c; + if (ch == '\0') + { + i = ft_strlen(str); + return ((char *)str + i++); + } + while (str[i]) + { + if (str[i] == ch) + return ((char *)str + i); + i++; + } + return (NULL); +} diff --git a/ft_strdup.c b/ft_strdup.c new file mode 100644 index 0000000..a81a9b6 --- /dev/null +++ b/ft_strdup.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/26 16:03:27 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 15:58:22 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_strdup duplicates the given string s1 by allocating + memory and performing a copy of the given string. + + RETURN VALUE : + A pointer to the new string. NULL if the memory allocation fails. +*/ + +char *ft_strdup(const char *s1) +{ + char *s2; + size_t len; + + len = ft_strlen(s1) + 1; + s2 = malloc(len * sizeof(char)); + if (!s2) + return (NULL); + ft_strlcpy(s2, s1, len); + return (s2); +} diff --git a/ft_striteri.c b/ft_striteri.c new file mode 100644 index 0000000..7ff6991 --- /dev/null +++ b/ft_striteri.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/28 05:10:58 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 16:00:25 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_striteri applies the given function f to each + character in the given string s. + + RETURN VALUE : + None. +*/ + +void ft_striteri(char *s, void (*f)(unsigned int, char*)) +{ + int i; + + if (!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..4c42cec --- /dev/null +++ b/ft_strjoin.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/26 18:18:15 by mcombeau #+# #+# */ +/* Updated: 2021/12/06 15:09:40 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_strjoin concatenates the given strings s1 and s2 + and allocates sufficient memory for the newly created string. + + RETURN VALUE : + A pointer to the new concatenated string. + NULL if the memory allocation fails. +*/ + +char *ft_strjoin(char const *s1, char const *s2) +{ + char *s; + size_t len; + int i; + + len = ft_strlen(s1) + ft_strlen(s2); + s = ft_calloc(len + 1, sizeof(char)); + if (!s) + return (NULL); + len = 0; + while (s1[len]) + { + s[len] = s1[len]; + len++; + } + i = 0; + while (s2[i]) + { + s[len + i] = s2[i]; + i++; + } + return (s); +} diff --git a/ft_strlcat.c b/ft_strlcat.c new file mode 100644 index 0000000..7d9a38b --- /dev/null +++ b/ft_strlcat.c @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/24 15:14:19 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 16:13:28 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_strlcat appends the given string src to the end of + dst. It will append at most dstsize - ft_strlen(dst) - 1 and + nul-terminate the result. + + Note : space for the terminating \0 character must be included in dstsize. + + RETURN VALUE : + The total length of the string that it tried to create : the initial + length of dst + the length of src, with the goal to facilitate + truncaction detection. +*/ + +size_t ft_strlcat(char *dst, const char *src, size_t dstsize) +{ + size_t i; + size_t j; + size_t d_size; + size_t s_size; + + d_size = ft_strlen(dst); + s_size = ft_strlen(src); + if (dstsize <= d_size) + return (dstsize + s_size); + i = d_size; + j = 0; + while ((i + j) < (dstsize - 1) && src[j] != '\0') + { + dst[i + j] = src[j]; + j++; + } + dst[i + j] = '\0'; + return (d_size + s_size); +} diff --git a/ft_strlcpy.c b/ft_strlcpy.c new file mode 100644 index 0000000..7061980 --- /dev/null +++ b/ft_strlcpy.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/24 14:16:24 by mcombeau #+# #+# */ +/* Updated: 2021/12/03 16:32:30 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_strlcpy copies up to size - 1 characters from the given + string src to the given string dst, nul-terminating the result. + + Note : space for the terminating \0 character must be included in dstsize. + + RETURN VALUE : + The total length of the string that it tried to create : the length of + src, with the goal to facilitate truncaction detection. +*/ + +size_t ft_strlcpy(char *dst, const char *src, size_t dstsize) +{ + size_t i; + size_t srclen; + + srclen = ft_strlen(src); + if (dstsize == 0) + return (srclen); + i = 0; + while (i < (dstsize - 1) && src[i] != '\0') + { + dst[i] = src[i]; + i++; + } + dst[i] = '\0'; + return (srclen); +} diff --git a/ft_strlen.c b/ft_strlen.c new file mode 100644 index 0000000..1963dc0 --- /dev/null +++ b/ft_strlen.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/22 13:51:11 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 16:17:56 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_strlen measures the length of the given string str, + excluding the terminating \0 character. + + RETURN VALUE : + The number of bytes in the string str. +*/ + +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..9c88e54 --- /dev/null +++ b/ft_strmapi.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/28 04:35:39 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 16:21:12 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESRIPTION : + The function ft_strmapi applies the given function f to each character + in the given string s and allocates sufficient memory to store the + resulting new string. + + RETURN VALUE : + A pointer to the newly created string. NULL if the memory allocation + fails. +*/ + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + char *str; + unsigned int i; + + if (!s || (!s && !f)) + return (ft_strdup("")); + else if (!f) + return (ft_strdup(s)); + str = ft_strdup(s); + if (!str) + return (NULL); + i = 0; + while (s[i]) + { + str[i] = (*f)(i, s[i]); + i++; + } + return (str); +} diff --git a/ft_strncmp.c b/ft_strncmp.c new file mode 100644 index 0000000..c03fba3 --- /dev/null +++ b/ft_strncmp.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/24 17:09:14 by mcombeau #+# #+# */ +/* Updated: 2021/12/06 15:15:37 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_strncmp compares the first n bytes of the given strings + s1 and s2. + + RETURN VALUE : + An integer less than, equal to, or greater than zero if one of the first + n bytes of s1 is found to be less than, to match, or to be greater than + s2. +*/ + +int ft_strncmp(const char *s1, const char *s2, size_t n) +{ + size_t i; + + i = 0; + if (n == 0) + return (0); + while ((s1[i] != '\0' && s2[i] != '\0') + && (i < n - 1) && s1[i] == s2[i]) + i++; + return ((unsigned char)s1[i] - (unsigned char)s2[i]); +} diff --git a/ft_strnstr.c b/ft_strnstr.c new file mode 100644 index 0000000..c26fd5f --- /dev/null +++ b/ft_strnstr.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/25 23:07:33 by mcombeau #+# #+# */ +/* Updated: 2021/12/03 16:33:24 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_strnstr searches the first n bytes of the given string + s1 for the first occurence of the full string s2. + Characters that appear after \0 are not searched. + + RETURN VALUE : + A pointer to the first character of the first occurrence of s2. + A pointer to s1 if s2 is empty. + NULL if s2 occurs nowhere in s1. +*/ + +char *ft_strnstr(const char *s1, const char *s2, size_t n) +{ + size_t s2len; + size_t i; + size_t j; + + s2len = ft_strlen(s2); + if (s1 == s2 || s2len == 0) + return ((char *)s1); + i = 0; + while (i < n && s1[i] != '\0') + { + j = 0; + while (s1[i + j] != '\0' && s2[j] != '\0' + && (i + j) < n && s1[i + j] == s2[j]) + { + j++; + if ((j == n && j == s2len) || j == s2len) + return ((char *)(s1 + i)); + } + i++; + } + return (0); +} diff --git a/ft_strrchr.c b/ft_strrchr.c new file mode 100644 index 0000000..aa24b80 --- /dev/null +++ b/ft_strrchr.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/24 15:50:46 by mcombeau #+# #+# */ +/* Updated: 2021/12/05 15:37:01 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_strrchr finds the last occurrence of character c in + string str. + + RETURN VALUE : + A pointer to the last occurrence of c in str. + NULL if c is not found. +*/ + +char *ft_strrchr(const char *str, int c) +{ + char *p; + unsigned char ch; + size_t offset; + + ch = c; + offset = ft_strlen(str); + p = (char *)str + offset; + if (ch == '\0') + return (p++); + while (p >= str) + { + if (*p == ch) + return (p); + p--; + } + p = NULL; + return (p); +} diff --git a/ft_strtrim.c b/ft_strtrim.c new file mode 100644 index 0000000..591703a --- /dev/null +++ b/ft_strtrim.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/27 16:51:42 by mcombeau #+# #+# */ +/* Updated: 2021/12/03 16:21:52 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_strtrim removes any characters of the given set from + the beginning and end of the given string s1, and allocates sufficient + memory to store the trimmed copy of the string. + + RETURN VALUE : + A pointer to the trimmed copy of the string. + NULL if the memory allocation fails. +*/ + +static int is_set(char c, char const *set) +{ + int i; + + i = 0; + while (set[i]) + { + if (set[i] == c) + return (1); + i++; + } + return (0); +} + +char *ft_strtrim(char const *s1, char const *set) +{ + size_t start; + size_t end; + + if (!s1) + return (ft_strdup("")); + if (!set) + return (ft_strdup(s1)); + start = 0; + end = ft_strlen(s1); + while (is_set(s1[start], set)) + start++; + if (start == end) + return (ft_strdup("")); + while (is_set(s1[end - 1], set)) + end--; + return (ft_substr(s1, start, end - start)); +} diff --git a/ft_substr.c b/ft_substr.c new file mode 100644 index 0000000..46b314b --- /dev/null +++ b/ft_substr.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/26 16:50:44 by mcombeau #+# #+# */ +/* Updated: 2021/12/02 16:53:34 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_substr extracts a substring from the given string by + allocating sufficient memory for the new string starting at index start + and ending at len characters. + + RETURN VALUE : + A pointer to the new string. + NULL if the memory allocation fails. +*/ + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + char *res; + char *src; + size_t reslen; + + if (!s) + return (NULL); + if (ft_strlen(s) < (size_t)start) + return (ft_strdup("")); + src = (char *)s + start; + if (ft_strlen(src) < len) + reslen = ft_strlen(src) + 1; + else + reslen = len + 1; + res = malloc(reslen * sizeof(char)); + if (!res) + return (NULL); + ft_strlcpy(res, src, reslen); + return (res); +} diff --git a/ft_tolower.c b/ft_tolower.c new file mode 100644 index 0000000..ec0637f --- /dev/null +++ b/ft_tolower.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/22 13:52:04 by mcombeau #+# #+# */ +/* Updated: 2021/12/06 15:42:20 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_tolower converts a given uppercase letter c to its + lowercase equivalent. + + RETURN VALUE : + The lowercase equivalent letter. + The original character c if c is not an uppercase letter. +*/ + +int ft_tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + c += 32; + return (c); +} diff --git a/ft_toupper.c b/ft_toupper.c new file mode 100644 index 0000000..ffa8aa7 --- /dev/null +++ b/ft_toupper.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/22 13:53:56 by mcombeau #+# #+# */ +/* Updated: 2021/12/06 15:41:08 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* + DESCRIPTION : + The function ft_toupper converts a given lowercase letter c to its + uppercase equivalent. + + RETURN VALUE : + The uppercase equivalent letter. + The original character c if c is not a lowercase letter. +*/ + +int ft_toupper(int c) +{ + if (c >= 'a' && c <= 'z') + c -= 32; + return (c); +} diff --git a/libft.h b/libft.h new file mode 100644 index 0000000..f0d1c95 --- /dev/null +++ b/libft.h @@ -0,0 +1,81 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/22 13:54:20 by mcombeau #+# #+# */ +/* Updated: 2021/12/04 13:57:17 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +# include +# include +# include + +/* --------------- LISTS --------------- */ +typedef struct s_list +{ + void *content; + struct s_list *next; +} t_list; + +t_list *ft_lstnew(void *content); +void ft_lstadd_front(t_list **alst, t_list *new); +int ft_lstsize(t_list *lst); +t_list *ft_lstlast(t_list *lst); +void ft_lstadd_back(t_list **alst, 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 *)); + +/* --------------- CHARS --------------- */ +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_toupper(int c); +int ft_tolower(int c); + +/* --------------- STRINGS --------------- */ +size_t ft_strlen(const char *str); +char *ft_strchr(const char *str, int c); +char *ft_strrchr(const char *str, int c); +size_t ft_strlcpy(char *dst, const char *src, size_t dstsize); +size_t ft_strlcat(char *dst, const char *src, size_t dstsize); +int ft_strncmp(const char *s1, const char *s2, size_t n); +char *ft_strnstr(const char *s1, const char *s2, 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_strmapi(char const *s, char (*f)(unsigned int, char)); +void ft_striteri(char *s, void (*f)(unsigned int, char*)); + +/* --------------- FILE DESCRIPTORS --------------- */ +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); + +/* --------------- MEMORY --------------- */ +void *ft_memset(void *b, int c, size_t len); +void ft_bzero(void *s, size_t n); +void *ft_memcpy(void *dst, const void *src, size_t n); +void *ft_memmove(void *dst, const void *src, size_t len); +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_calloc(size_t count, size_t size); + +/* --------------- NUMBERS --------------- */ +int ft_atoi(const char *str); +char *ft_itoa(int n); + +#endif diff --git a/subject/subject_en_libft.pdf b/subject/subject_en_libft.pdf new file mode 100644 index 0000000..3d4c996 Binary files /dev/null and b/subject/subject_en_libft.pdf differ diff --git a/subject/subject_fr_libft.pdf b/subject/subject_fr_libft.pdf new file mode 100644 index 0000000..d68b578 Binary files /dev/null and b/subject/subject_fr_libft.pdf differ diff --git a/testing/Makefile b/testing/Makefile new file mode 100644 index 0000000..0f30615 --- /dev/null +++ b/testing/Makefile @@ -0,0 +1,35 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: mcombeau +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2021/11/22 13:48:30 by mcombeau #+# #+# # +# Updated: 2021/12/03 13:58:37 by mcombeau ### ########.fr # +# # +# **************************************************************************** # + +NAME = test +CC = gcc +CFLAGS = -Wall -Werror -Wextra -g3 +LIBFT_PATH = "../" + +$(NAME): make_libft + $(CC) $(CFLAGS) -o $(NAME) $(LIBFT_PATH)*.o main.c + +make_libft: + make bonus -C $(LIBFT_PATH) + +all: $(NAME) + + +clean: + rm -f $(OBJS) + +fclean: clean + rm -f $(NAME) + +re: clean all + +.PHONY: all clean fclean re diff --git a/testing/main.c b/testing/main.c new file mode 100644 index 0000000..912f4fd --- /dev/null +++ b/testing/main.c @@ -0,0 +1,1405 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcombeau +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/11/22 13:55:32 by mcombeau #+# #+# */ +/* Updated: 2021/12/07 12:12:51 by mcombeau ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include +#include +#include +#include "../libft.h" +#include +# include +# include +# include + +/* + * Check if allowed for functions with size_t (ft_memset). + * Check why original function segfaults but ft doesn't. + * Test MEMSET more + * FIX MEMMOVE!!!!! + * + * + * + * + * */ + +void ft_putstr(char *s) +{ + while (*s != '\0') + write(1, s++, 1); +} + +void test_isalpha(void) +{ + printf("=========== TESTING IS ALPHA ============\n\n"); + char c; + + printf("char\t:\tReal\t:\tFT\n"); + c = 'a'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalpha(c), (ft_isalpha(c) != 0) ? 1 : 0); + c = 'A'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalpha(c), (ft_isalpha(c) != 0) ? 1 : 0); + c = 'z'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalpha(c), (ft_isalpha(c) != 0) ? 1 : 0); + c = 'Z'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalpha(c), (ft_isalpha(c) != 0) ? 1 : 0); + c = 's'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalpha(c), (ft_isalpha(c) != 0) ? 1 : 0); + c = 'F'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalpha(c), (ft_isalpha(c) != 0) ? 1 : 0); + c = ' '; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalpha(c), (ft_isalpha(c) != 0) ? 1 : 0); + c = '3'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalpha(c), (ft_isalpha(c) != 0) ? 1 : 0); + c = ','; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalpha(c), (ft_isalpha(c) != 0) ? 1 : 0); + c = 0; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalpha(c), (ft_isalpha(c) != 0) ? 1 : 0); + c = '`'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalpha(c), (ft_isalpha(c) != 0) ? 1 : 0); + c = '{'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalpha(c), (ft_isalpha(c) != 0) ? 1 : 0); + c = '@'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalpha(c), (ft_isalpha(c) != 0) ? 1 : 0); + c = '['; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalpha(c), (ft_isalpha(c) != 0) ? 1 : 0); +} + +void test_isdigit(void) +{ + printf("\n\n=========== TESTING IS DIGIT ============\n\n"); + char c; + + printf("char\t:\tReal\t:\tFT\n"); + c = '0'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isdigit(c), (ft_isdigit(c) != 0) ? 1 : 0); + c = '9'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isdigit(c), (ft_isdigit(c) != 0) ? 1 : 0); + c = '6'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isdigit(c), (ft_isdigit(c) != 0) ? 1 : 0); + c = 'f'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isdigit(c), (ft_isdigit(c) != 0) ? 1 : 0); + c = '\\'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isdigit(c), (ft_isdigit(c) != 0) ? 1 : 0); + c = ':'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isdigit(c), (ft_isdigit(c) != 0) ? 1 : 0); + c = -1; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isdigit(c), (ft_isdigit(c) != 0) ? 1 : 0); +} + +void test_isalnum(void) +{ + printf("\n\n=========== TESTING IS ALPHANUMERIC ============\n\n"); + char c; + + printf("char\t:\tReal\t:\tFT\n"); + c = 'a'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalnum(c), (ft_isalnum(c) != 0) ? 1 : 0); + c = 'z'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalnum(c), (ft_isalnum(c) != 0) ? 1 : 0); + c = 'A'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalnum(c), (ft_isalnum(c) != 0) ? 1 : 0); + c = 'Z'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalnum(c), (ft_isalnum(c) != 0) ? 1 : 0); + c = '0'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalnum(c), (ft_isalnum(c) != 0) ? 1 : 0); + c = '9'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalnum(c), (ft_isalnum(c) != 0) ? 1 : 0); + c = 'm'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalnum(c), (ft_isalnum(c) != 0) ? 1 : 0); + c = 'L'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalnum(c), (ft_isalnum(c) != 0) ? 1 : 0); + c = '6'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalnum(c), (ft_isalnum(c) != 0) ? 1 : 0); + c = '@'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalnum(c), (ft_isalnum(c) != 0) ? 1 : 0); + c = '['; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalnum(c), (ft_isalnum(c) != 0) ? 1 : 0); + c = '`'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalnum(c), (ft_isalnum(c) != 0) ? 1 : 0); + c = '{'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalnum(c), (ft_isalnum(c) != 0) ? 1 : 0); + c = '\\'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalnum(c), (ft_isalnum(c) != 0) ? 1 : 0); + c = ':'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isalnum(c), (ft_isalnum(c) != 0) ? 1 : 0); +} + +void test_isascii(void) +{ + printf("\n\n=========== TESTING IS ASCII ============\n\n"); + char c; + + printf("char\t:\tReal\t:\tFT\n"); + c = 0; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isascii(c), (ft_isascii(c) != 0) ? 1 : 0); + c = 127; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isascii(c), (ft_isascii(c) != 0) ? 1 : 0); + c = 'a'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isascii(c), (ft_isascii(c) != 0) ? 1 : 0); + c = -1; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isascii(c), (ft_isascii(c) != 0) ? 1 : 0); + c = -30; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isascii(c), (ft_isascii(c) != 0) ? 1 : 0); +} + +void test_isprint(void) +{ + printf("\n\n=========== TESTING IS PRINT ============\n\n"); + char c; + + printf("char\t:\tReal\t:\tFT\n"); + c = ' '; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isprint(c), (ft_isprint(c) != 0) ? 1 : 0); + c = '~'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isprint(c), (ft_isprint(c) != 0) ? 1 : 0); + c = 'a'; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isprint(c), (ft_isprint(c) != 0) ? 1 : 0); + c = 43; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isprint(c), (ft_isprint(c) != 0) ? 1 : 0); + c = 31; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isprint(c), (ft_isprint(c) != 0) ? 1 : 0); + c = 127; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isprint(c), (ft_isprint(c) != 0) ? 1 : 0); + c = -1; + printf("\'%c\'\t:\t%d\t:\t%d\n", c, isprint(c), (ft_isprint(c) != 0) ? 1 : 0); +} + +void test_strlen(void) +{ + printf("\n\n=========== TESTING STRLEN ============\n\n"); + + if (strlen("Hello") == ft_strlen("Hello")) + printf("OK: expected %zu, got %zu. [test string \"Hello\".]\n", strlen("Hello"), ft_strlen("Hello")); + else + printf("Try again: expected %zu, got %zu [test string \" \".]\n", strlen("Hello"), ft_strlen("Hello")); + + if (strlen(" ") == ft_strlen(" ")) + printf("OK: expected %zu, got %zu. [test string \" \".]\n", strlen(" "), ft_strlen(" ")); + else + printf("Try again: expected %zu, got %zu [test string \" \".]\n", strlen(" "), ft_strlen(" ")); + + + if (strlen("") == ft_strlen("")) + printf("OK: expected %zu, got %zu. [test string \"\".]\n", strlen(""), ft_strlen("")); + else + printf("Try again: expected %zu, got %zu [test string \"\".]\n", strlen(""), ft_strlen("")); + + if (strlen("123456789123456789") == ft_strlen("123456789123456789")) + printf("OK: expected %zu, got %zu. [test string \"123456789123456789\".]\n", strlen("123456789123456789"), ft_strlen("123456789123456789")); + else + printf("Try again: expected %zu, got %zu [test string \"123456789123456789\".]\n", strlen("123456789123456789"), ft_strlen("123456789123456789")); + + if (strlen("\0") == ft_strlen("\0")) + printf("OK: expected %zu, got %zu. [test string \"\\0\".]\n", strlen("\0"), ft_strlen("\0")); + else + printf("Try again: expected %zu, got %zu [test string \"\\0\".]\n", strlen("\0"), ft_strlen("\0")); +} + +void test_memset(void) +{ + printf("\n\n=========== TESTING MEMSET ============\n\n"); + + char orsrc[20] = "Hello World"; + char ftsrc[20] = "Hello World"; + + if(!strcmp(memset(orsrc, 'o', 3), ft_memset(ftsrc, 'o', 3))) + printf("OK: expected \"%s\", got \"%s\".\n", orsrc, ftsrc); + else + printf("Try again: expected \"%s\", got \"%s\".\n", orsrc, ftsrc); + if(!strcmp(memset(orsrc, 'x', 15), ft_memset(ftsrc, 'x', 15))) + printf("OK: expected \"%s\", got \"%s\".\n", orsrc, ftsrc); + else + printf("Try again: expected \"%s\", got \"%s\".\n", orsrc, ftsrc); + if(!strcmp(memset(orsrc, '~', 5), ft_memset(ftsrc, '~', 5))) + printf("OK: expected \"%s\", got \"%s\".\n", orsrc, ftsrc); + else + printf("Try again: expected \"%s\", got \"%s\".\n", orsrc, ftsrc); +} + +void test_bzero(void) +{ + printf("\n\n=========== TESTING BZERO ============\n\n"); + + char sori[20] = "abcdef"; + char sft[20] = "abcdef"; + bzero(sori, 4); + ft_bzero(sft, 4); + int i; + i = 0; + + while (i < 6 && sori[i] == sft[i]) + i++; + if (i == 6) + printf("OK: expected [%c] [%c] [%c] [%c] [%c] [%c], got [%c] [%c] [%c] [%c] [%c] [%c].\n", sori[0], sori[1], sori[2], sori[3], sori[4], sori[5], sft[0], sft[1], sft[2], sft[3], sft[4], sft[5]); + + else + printf("Try again: expected [%c] [%c] [%c] [%c] [%c] [%c], got [%c] [%c] [%c] [%c] [%c] [%c].\n", sori[0], sori[1], sori[2], sori[3], sori[4], sori[5], sft[0], sft[1], sft[2], sft[3], sft[4], sft[5]); +} + +void test_memcpy(void) +{ + printf("\n\n=========== TESTING MEMCPY ============\n\n"); + + char dest0[20] = "World"; + char dest1[20] = "World"; + + if(!strcmp(memcpy(dest0, "source", 3), ft_memcpy(dest1, "source", 3))) + printf("OK: expected \"%s\", got \"%s\".\n", dest0, dest1); + else + printf("Try again: expected \"%s\", got \"%s\".\n", dest0, dest1); + if(!strcmp(memcpy(dest0, "123456source", 9), ft_memcpy(dest1, "123456source", 9))) + printf("OK: expected \"%s\", got \"%s\".\n", dest0, dest1); + else + printf("Try again: expected \"%s\", got \"%s\".\n", dest0, dest1); + if(!strcmp(memcpy(dest0, "123456source", 0), ft_memcpy(dest1, "123456source", 0))) + printf("OK: expected \"%s\", got \"%s\".\n", dest0, dest1); + else + printf("Try again: expected \"%s\", got \"%s\".\n", dest0, dest1); +} + +void test_memmove(void) +{ + printf("\n\n=========== TESTING MEMMOVE ============\n\n"); + + char srcdest[20] = "a1b2c3d4e5f6g7"; + char ftsrcdest[20] = "a1b2c3d4e5f6g7"; + + if (!strcmp((char *)memmove(srcdest + 2, srcdest, 7), (char *)ft_memmove(ftsrcdest +2, ftsrcdest, 7))) + printf("OK: expected \"%s\", got \"%s\".\n", srcdest, ftsrcdest); + else + printf("Try again: expected \"%s\", got \"%s\".\n", srcdest, ftsrcdest); + + if (!strcmp((char *)memmove(srcdest + 4, srcdest, 7), (char *)ft_memmove(ftsrcdest +4, ftsrcdest, 7))) + printf("OK: expected \"%s\", got \"%s\".\n", srcdest, ftsrcdest); + else + printf("Try again: expected \"%s\", got \"%s\".\n", srcdest, ftsrcdest); + + if (!strcmp((char *)memmove(srcdest, srcdest + 8, 7), (char *)ft_memmove(ftsrcdest, ftsrcdest + 8, 7))) + printf("OK: expected \"%s\", got \"%s\".\n", srcdest, ftsrcdest); + else + printf("Try again: expected \"%s\", got \"%s\".\n", srcdest, ftsrcdest); + + if (!strcmp((char *)memmove(srcdest + 2, srcdest, 0), (char *)ft_memmove(ftsrcdest +2, ftsrcdest, 0))) + printf("OK: expected \"%s\", got \"%s\".\n", srcdest, ftsrcdest); + else + printf("Try again: expected \"%s\", got \"%s\".\n", srcdest, ftsrcdest); + + if (!strcmp((char *)memmove(srcdest, srcdest, 5), (char *)ft_memmove(ftsrcdest, ftsrcdest, 5))) + printf("OK: expected \"%s\", got \"%s\".\n", srcdest, ftsrcdest); + else + printf("Try again: expected \"%s\", got \"%s\".\n", srcdest, ftsrcdest); + +} +/* +void test_strlcpy(void) +{ + printf("\n\n=========== TESTING STRLCPY ============\n\n"); + + char dstor[20] = "Hello World!"; + char dstft[20] = "Hello World!"; + + if ((strlcpy(dstor, "123456789", 5) == ft_strlcpy(dstft, "123456789", 5)) && !strcmp(dstor, dstft)) + printf("OK: expected \"%s\", got \"%s\".\n", dstor, dstft); + else + printf("Try again: expected \"%s\", got \"%s\".\n", dstor, dstft); + + if ((strlcpy(dstor, "", 5) == ft_strlcpy(dstft, "", 5)) && !strcmp(dstor, dstft)) + printf("OK: expected \"%s\", got \"%s\".\n", dstor, dstft); + else + printf("Try again: expected \"%s\", got \"%s\".\n", dstor, dstft); + + if ((strlcpy(dstor, "Help", 4) == ft_strlcpy(dstft, "Help", 4)) && !strcmp(dstor, dstft)) + printf("OK: expected \"%s\", got \"%s\".\n", dstor, dstft); + else + printf("Try again: expected \"%s\", got \"%s\".\n", dstor, dstft); +} + +void test_strlcat(void) +{ + printf("\n\n=========== TESTING STRLCAT ============\n\n"); + + char catdstor[20] = "123"; + char catdstft[20] = "123"; + + if ((strlcat(catdstor, "Hey", 4) == strlcat(catdstft, "Hey", 4)) && !strcmp(catdstor, catdstft)) + printf("OK: expected \"%s\", got \"%s\".\n", catdstor, catdstft); + else + printf("Try again: expected \"%s\", got \"%s\".\n", catdstor, catdstft); + + if ((strlcat(catdstor, "CoucouCommentVa", 15) == strlcat(catdstft, "CoucouCommentVa", 15)) && !strcmp(catdstor, catdstft)) + printf("OK: expected \"%s\", got \"%s\".\n", catdstor, catdstft); + else + printf("Try again: expected \"%s\", got \"%s\".\n", catdstor, catdstft); + + if ((strlcat(catdstor, "xx", 20) == strlcat(catdstft, "xx", 20)) && !strcmp(catdstor, catdstft)) + printf("OK: expected \"%s\", got \"%s\".\n", catdstor, catdstft); + else + printf("Try again: expected \"%s\", got \"%s\".\n", catdstor, catdstft); + + if ((strlcat(catdstor, "o", 2) == strlcat(catdstft, "o", 2)) && !strcmp(catdstor, catdstft)) + printf("OK: expected \"%s\", got \"%s\".\n", catdstor, catdstft); + else + printf("Try again: expected \"%s\", got \"%s\".\n", catdstor, catdstft); +} +*/ +void test_toupper(void) +{ + printf("\n\n=========== TESTING TO UPPER ============\n\n"); + char c; + + printf("char\t:\tReal\t:\tFT\n"); + c = 'a'; + printf("\'%c\'\t:\t\'%c\'\t:\t\'%c\'\n", c, toupper(c), ft_toupper(c)); + c = 'w'; + printf("\'%c\'\t:\t\'%c\'\t:\t\'%c\'\n", c, toupper(c), ft_toupper(c)); + c = 'A'; + printf("\'%c\'\t:\t\'%c\'\t:\t\'%c\'\n", c, toupper(c), ft_toupper(c)); + c = ' '; + printf("\'%c\'\t:\t\'%c\'\t:\t\'%c\'\n", c, toupper(c), ft_toupper(c)); + c = '3'; + printf("\'%c\'\t:\t\'%c\'\t:\t\'%c\'\n", c, toupper(c), ft_toupper(c)); + c = '~'; + printf("\'%c\'\t:\t\'%c\'\t:\t\'%c\'\n", c, toupper(c), ft_toupper(c)); + c = '*'; + printf("\'%c\'\t:\t\'%c\'\t:\t\'%c\'\n", c, toupper(c), ft_toupper(c)); +} + +void test_tolower(void) +{ + printf("\n\n=========== TESTING TO LOWER ============\n\n"); + char c; + + printf("char\t:\tReal\t:\tFT\n"); + c = 'A'; + printf("\'%c\'\t:\t\'%c\'\t:\t\'%c\'\n", c, tolower(c), ft_tolower(c)); + c = 'W'; + printf("\'%c\'\t:\t\'%c\'\t:\t\'%c\'\n", c, tolower(c), ft_tolower(c)); + c = 'a'; + printf("\'%c\'\t:\t\'%c\'\t:\t\'%c\'\n", c, tolower(c), ft_tolower(c)); + c = ' '; + printf("\'%c\'\t:\t\'%c\'\t:\t\'%c\'\n", c, tolower(c), ft_tolower(c)); + c = '3'; + printf("\'%c\'\t:\t\'%c\'\t:\t\'%c\'\n", c, tolower(c), ft_tolower(c)); + c = '~'; + printf("\'%c\'\t:\t\'%c\'\t:\t\'%c\'\n", c, tolower(c), ft_tolower(c)); + c = '*'; + printf("\'%c\'\t:\t\'%c\'\t:\t\'%c\'\n", c, tolower(c), ft_tolower(c)); +} + +void test_strchr(void) +{ + printf("\n\n=========== TESTING STRCHR ============\n\n"); + + char *str = "Coucou la ville!"; + + if (!strcmp(strchr(str, 'C'), ft_strchr(str, 'C'))) + printf("OK: expected \"%s\", got \"%s\".\n", strchr(str, 'C'), ft_strchr(str, 'C')); + else + printf("Try again: expected \"%s\", got \"%s\".\n", strchr(str, 'C'), ft_strchr(str, 'C')); + + if (!strcmp(strchr(str, 'u'), ft_strchr(str, 'u'))) + printf("OK: expected \"%s\", got \"%s\".\n", strchr(str, 'u'), ft_strchr(str, 'u')); + else + printf("Try again: expected \"%s\", got \"%s\".\n", strchr(str, 'u'), ft_strchr(str, 'u')); + + if (!strcmp(strchr(str, 'v'), ft_strchr(str, 'v'))) + printf("OK: expected \"%s\", got \"%s\".\n", strchr(str, 'v'), ft_strchr(str, 'v')); + else + printf("Try again: expected \"%s\", got \"%s\".\n", strchr(str, 'v'), ft_strchr(str, 'v')); + + if (!strcmp(strchr(str, 'l'), ft_strchr(str, 'l'))) + printf("OK: expected \"%s\", got \"%s\".\n", strchr(str, 'l'), ft_strchr(str, 'l')); + else + printf("Try again: expected \"%s\", got \"%s\".\n", strchr(str, 'l'), ft_strchr(str, 'l')); + + if (!strcmp(strchr(str, '\0'), ft_strchr(str, '\0'))) + printf("OK: expected \"%s\", got \"%s\".\n", strchr(str, '\0'), ft_strchr(str, '\0')); + else + printf("Try again: expected \"%s\", got \"%s\".\n", strchr(str, '\0'), ft_strchr(str, '\0')); + + + if (strchr(str, 'x') == ft_strchr(str, 'x')) + printf("OK: expected \"%s\", got \"%s\".\n", strchr(str, 'x'), ft_strchr(str, 'x')); + else + printf("Try again: expected \"%s\", got \"%s\".\n", strchr(str, 'x'), ft_strchr(str, 'x')); +} + +void test_strrchr(void) +{ + printf("\n\n=========== TESTING STRRCHR ============\n\n"); + + char *strr = "Coucou la ville!"; + + if (!strcmp(strrchr(strr, 'C'), ft_strrchr(strr, 'C'))) + printf("OK: expected \"%s\", got \"%s\".\n", strrchr(strr, 'C'), ft_strrchr(strr, 'C')); + else + printf("Try again: expected \"%s\", got \"%s\".\n", strrchr(strr, 'C'), ft_strrchr(strr, 'C')); + + if (!strcmp(strrchr(strr, 'u'), ft_strrchr(strr, 'u'))) + printf("OK: expected \"%s\", got \"%s\".\n", strrchr(strr, 'u'), ft_strrchr(strr, 'u')); + else + printf("Try again: expected \"%s\", got \"%s\".\n", strrchr(strr, 'u'), ft_strrchr(strr, 'u')); + + if (!strcmp(strrchr(strr, 'v'), ft_strrchr(strr, 'v'))) + printf("OK: expected \"%s\", got \"%s\".\n", strrchr(strr, 'v'), ft_strrchr(strr, 'v')); + else + printf("Try again: expected \"%s\", got \"%s\".\n", strrchr(strr, 'v'), ft_strrchr(strr, 'v')); + + if (!strcmp(strrchr(strr, 'l'), ft_strrchr(strr, 'l'))) + printf("OK: expected \"%s\", got \"%s\".\n", strrchr(strr, 'l'), ft_strrchr(strr, 'l')); + else + printf("Try again: expected \"%s\", got \"%s\".\n", strrchr(strr, 'l'), ft_strrchr(strr, 'l')); + + if (!strcmp(strrchr(strr, '\0'), ft_strrchr(strr, '\0'))) + printf("OK: expected \"%s\", got \"%s\".\n", strrchr(strr, '\0'), ft_strrchr(strr, '\0')); + else + printf("Try again: expected \"%s\", got \"%s\".\n", strrchr(strr, '\0'), ft_strrchr(strr, '\0')); + + + if (strrchr(strr, 'x') == ft_strrchr(strr, 'x')) + printf("OK: expected \"%s\", got \"%s\".\n", strrchr(strr, 'x'), ft_strrchr(strr, 'x')); + else + printf("Try again: expected \"%s\", got \"%s\".\n", strrchr(strr, 'x'), ft_strrchr(strr, 'x')); +} + +void test_strncmp(void) +{ + printf("\n\n=========== TESTING STRNCMP ============\n\n"); + + char s1[50] = "Hello there are 75 days left."; + char s2[50] = "Hello there are 75 days left."; + + if (strncmp(s1, s2, 20) == ft_strncmp(s1, s2, 20)) + printf("OK: expected %d, got %d.\n", strncmp(s1, s2, 20), ft_strncmp(s1, s2, 20)); + else + printf("Try again: expected %d, got %d.\n", strncmp(s1, s2, 20), ft_strncmp(s1, s2, 20)); + + if (strncmp(s1, s2, 0) == ft_strncmp(s1, s2, 0)) + printf("OK: expected %d, got %d.\n", strncmp(s1, s2, 0), ft_strncmp(s1, s2, 0)); + else + printf("Try again: expected %d, got %d.\n", strncmp(s1, s2, 0), ft_strncmp(s1, s2, 0)); + + s2[14] = ' '; + if (strncmp(s1, s2, 20) == ft_strncmp(s1, s2, 20)) + printf("OK: expected %d, got %d.\n", strncmp(s1, s2, 20), ft_strncmp(s1, s2, 20)); + else + printf("Try again: expected %d, got %d.\n", strncmp(s1, s2, 20), ft_strncmp(s1, s2, 20)); + + s2[14] = '~'; + if (strncmp(s1, s2, 20) == ft_strncmp(s1, s2, 20)) + printf("OK: expected %d, got %d.\n", strncmp(s1, s2, 20), ft_strncmp(s1, s2, 20)); + else + printf("Try again: expected %d, got %d.\n", strncmp(s1, s2, 20), ft_strncmp(s1, s2, 20)); + + if (strncmp(s1, s2, 9) == ft_strncmp(s1, s2, 9)) + printf("OK: expected %d, got %d.\n", strncmp(s1, s2, 9), ft_strncmp(s1, s2, 9)); + else + printf("Try again: expected %d, got %d.\n", strncmp(s1, s2, 9), ft_strncmp(s1, s2, 9)); + + strcpy(s2, ""); + if (strncmp(s1, s2, 20) == ft_strncmp(s1, s2, 20)) + printf("OK: expected %d, got %d.\n", strncmp(s1, s2, 20), ft_strncmp(s1, s2, 20)); + else + printf("Try again: expected %d, got %d.\n", strncmp(s1, s2, 20), ft_strncmp(s1, s2, 20)); + + strcpy(s2, "Hello there are tree days left"); + if (strncmp(s1, s2, 20) == ft_strncmp(s1, s2, 20)) + printf("OK: expected %d, got %d.\n", strncmp(s1, s2, 20), ft_strncmp(s1, s2, 20)); + else + printf("Try again: expected %d, got %d.\n", strncmp(s1, s2, 20), ft_strncmp(s1, s2, 20)); +} +/* +void test_memchr(void) +{ + printf("\n\n=========== TESTING MEMCHR ============\n\n"); + + char *memstr = "Allons-y vite!"; + + if (!strcmp((char *)memchr(memstr, 'l', 5), (char *)ft_memchr(memstr, 'l', 5))) + printf("OK: expected \"%s\", got \"%s\".\n", (char *)memchr(memstr, 'l', 5), (char *)ft_memchr(memstr, 'l', 5)); + else + printf("Try again: expected \"%s\", got \"%s\".\n", (char *)memchr(memstr, 'l', 5), (char *)ft_memchr(memstr, 'l', 5)); + + if (!strcmp((char *)memchr(memstr, 'y', 10), (char *)ft_memchr(memstr, 'y', 10))) + printf("OK: expected \"%s\", got \"%s\".\n", (char *)memchr(memstr, 'y', 10), (char *)ft_memchr(memstr, 'y', 10)); + else + printf("Try again: expected \"%s\", got \"%s\".\n", (char *)memchr(memstr, 'y', 10), (char *)ft_memchr(memstr, 'y', 10)); + + if ((char *)memchr(memstr, 'y', 2) == 0 && ft_memchr(memstr, 'y', 2) == 0) + printf("OK: expected \"%p\", got \"%p\".\n", memchr(memstr, 'y', 2), ft_memchr(memstr, 'y', 2)); + else + printf("Try again: expected \"%p\", got \"%p\".\n", memchr(memstr, 'y', 2), ft_memchr(memstr, 'y', 2)); + + if (memchr(memstr, 'y', 0) == 0 && ft_memchr(memstr, 'y', 0) == 0) + printf("OK: expected \"%p\", got \"%p\".\n", memchr(memstr, 'y', 0), ft_memchr(memstr, 'y', 0)); + else + printf("Try again: expected \"%p\", got \"%p\".\n", memchr(memstr, 'y', 0), ft_memchr(memstr, 'y', 0)); + + if (memchr(memstr, 'x', 20) == 0 && ft_memchr(memstr, 'x', 20) == 0) + printf("OK: expected \"%p\", got \"%p\".\n", memchr(memstr, 'x', 20), ft_memchr(memstr, 'x', 20)); + else + printf("Try again: expected \"%p\", got \"%p\".\n", memchr(memstr, 'x', 20), ft_memchr(memstr, 'x', 20)); + + if (!strcmp((char *)memchr(memstr, '\0', 20), (char *)ft_memchr(memstr, '\0', 20))) + printf("OK: expected \"%s\", got \"%s\".\n", (char *)memchr(memstr, '\0', 20), (char *)ft_memchr(memstr, '\0', 20)); + else + printf("Try again: expected \"%s\", got \"%s\".\n", (char *)memchr(memstr, '\0', 20), (char *)ft_memchr(memstr, '\0', 20)); + + char memstr2[20] = "/|\x12\xff\x09\x42\2002\42|\\"; + int size = 10; + + if (memchr(memstr2, '\200', size) == ft_memchr(memstr2, '\200', size)) + printf("OK: expected \"%s\", got \"%s\".\n", memchr(memstr2, '\200', size), ft_memchr(memstr2, '\200', size)); + else + printf("Try again: expected \"%s\", got \"%s\".\n", memchr(memstr2, '\200', size), ft_memchr(memstr2, '\200', size)); +} +*/ +void test_memcmp(void) +{ + printf("\n\n=========== TESTING MEMCMP ============\n\n"); + + char s1[50] = "Just in time for doing c."; + char s2[50] = "Just in time for doing c."; + + if (memcmp(s1, s2, 20) == ft_memcmp(s1, s2, 20)) + printf("OK: expected %d, got %d.\n", memcmp(s1, s2, 20), ft_memcmp(s1, s2, 20)); + else + printf("Try again: expected %d, got %d.\n", memcmp(s1, s2, 20), ft_memcmp(s1, s2, 20)); + + if (memcmp(s1, s2, 0) == ft_memcmp(s1, s2, 0)) + printf("OK: expected %d, got %d.\n", memcmp(s1, s2, 0), ft_memcmp(s1, s2, 0)); + else + printf("Try again: expected %d, got %d.\n", memcmp(s1, s2, 0), ft_memcmp(s1, s2, 0)); + + s2[5] = 'x'; + if (memcmp(s1, s2, 20) == ft_memcmp(s1, s2, 20)) + printf("OK: expected %d, got %d.\n", memcmp(s1, s2, 20), ft_memcmp(s1, s2, 20)); + else + printf("Try again: expected %d, got %d.\n", memcmp(s1, s2, 20), ft_memcmp(s1, s2, 20)); + + if (memcmp(s1, s2, 4) == ft_memcmp(s1, s2, 4)) + printf("OK: expected %d, got %d.\n", memcmp(s1, s2, 4), ft_memcmp(s1, s2, 4)); + else + printf("Try again: expected %d, got %d.\n", memcmp(s1, s2, 4), ft_memcmp(s1, s2, 4)); + + s2[5] = '#'; + if (memcmp(s1, s2, 20) == ft_memcmp(s1, s2, 20)) + printf("OK: expected %d, got %d.\n", memcmp(s1, s2, 20), ft_memcmp(s1, s2, 20)); + else + printf("Try again: expected %d, got %d.\n", memcmp(s1, s2, 20), ft_memcmp(s1, s2, 20)); + + strcpy(s2, ""); + if (memcmp(s1, s2, 20) == ft_memcmp(s1, s2, 20)) + printf("OK: expected %d, got %d.\n", memcmp(s1, s2, 20), ft_memcmp(s1, s2, 20)); + else + printf("Try again: expected %d, got %d.\n", memcmp(s1, s2, 20), ft_memcmp(s1, s2, 20)); + + strcpy(s2, "Just in time for doing a."); + if (memcmp(s1, s2, 20) == ft_memcmp(s1, s2, 20)) + printf("OK: expected %d, got %d.\n", memcmp(s1, s2, 20), ft_memcmp(s1, s2, 20)); + else + printf("Try again: expected %d, got %d.\n", memcmp(s1, s2, 20), ft_memcmp(s1, s2, 20)); +} +/* +void test_strnstr(void) +{ + char haystack[25] = "Hello the world exists."; + char needle[25] = "the world"; + + if (strnstr(haystack, needle, 20) == ft_strnstr(haystack, needle, 20)) + printf("OK: expected \"%s\", got \"%s\".\n", strnstr(haystack, needle, 20), ft_strnstr(haystack, needle, 20)); + else + printf("Try again: expected \"%s\", got \"%s\".\n", strnstr(haystack, needle, 20), ft_strnstr(haystack, needle, 20)); + +} +*/ +void test_atoi(void) +{ + printf("\n\n=========== TESTING ATOI ============\n\n"); + + if (atoi("145") == ft_atoi("145")) + printf("OK: expected %d, got %d.\n", atoi("145"), ft_atoi("145")); + else + printf("Try again: expected %d, got %d.\n", atoi("145"), ft_atoi("145")); + + if (atoi("-52") == ft_atoi("-52")) + printf("OK: expected %d, got %d.\n", atoi("-52"), ft_atoi("-52")); + else + printf("Try again: expected %d, got %d.\n", atoi("-52"), ft_atoi("-52")); + + if (atoi("+200") == ft_atoi("+200")) + printf("OK: expected %d, got %d.\n", atoi("+200"), ft_atoi("+200")); + else + printf("Try again: expected %d, got %d.\n", atoi("+200"), ft_atoi("+200")); + + if (atoi(" 1") == ft_atoi(" 1")) + printf("OK: expected %d, got %d.\n", atoi(" 1"), ft_atoi(" 1")); + else + printf("Try again: expected %d, got %d.\n", atoi(" 1"), ft_atoi(" 1")); + + if (atoi("abc") == ft_atoi("abc")) + printf("OK: expected %d, got %d.\n", atoi("abc"), ft_atoi("abc")); + else + printf("Try again: expected %d, got %d.\n", atoi("abc"), ft_atoi("abc")); + + if (atoi(" 14n5") == ft_atoi(" 14n5")) + printf("OK: expected %d, got %d.\n", atoi(" 14n5"), ft_atoi(" 14n5")); + else + printf("Try again: expected %d, got %d.\n", atoi(" 14n5"), ft_atoi(" 14n5")); + + if (atoi("-2147483648") == ft_atoi("-2147483648")) + printf("OK: expected %d, got %d.\n", atoi("-2147483648"), ft_atoi("-2147483648")); + else + printf("Try again: expected %d, got %d.\n", atoi("-2147483648"), ft_atoi("-2147483648")); + + + if (atoi("2147483700") == ft_atoi("2147483700")) + printf("OK: expected %d, got %d.\n", atoi("2147483700"), ft_atoi("2147483700")); + else + printf("Try again: expected %d, got %d.\n", atoi("2147483700"), ft_atoi("2147483700")); +} + +void test_strdup(void) +{ + printf("\n\n=========== TESTING STRDUP ============\n\n"); + + char tocpy[22] = "Duplication in action."; + char *orcpy; + char *ftcpy; + + orcpy = strdup(tocpy); + ftcpy = ft_strdup(tocpy); + if (!strcmp(orcpy, ftcpy)) + printf("OK: expected \"%s\", got \"%s\".\n", orcpy, ftcpy); + else + printf("Try again: expected \"%s\", got \"%s\".\n", orcpy, ftcpy); + free(orcpy); + free(ftcpy); + + + orcpy = strdup(tocpy + 18); + ftcpy = ft_strdup(tocpy + 18); + if (!strcmp(orcpy, ftcpy)) + printf("OK: expected \"%s\", got \"%s\".\n", orcpy, ftcpy); + else + printf("Try again: expected \"%s\", got \"%s\".\n", orcpy, ftcpy); + free(orcpy); + free(ftcpy); + + orcpy = strdup("Hello"); + ftcpy = ft_strdup("Hello"); + if (!strcmp(orcpy, ftcpy)) + printf("OK: expected \"%s\", got \"%s\".\n", orcpy, ftcpy); + else + printf("Try again: expected \"%s\", got \"%s\".\n", orcpy, ftcpy); + free(orcpy); + free(ftcpy); + + + orcpy = strdup(""); + ftcpy = ft_strdup(""); + if (!strcmp(orcpy, ftcpy)) + printf("OK: expected \"%s\", got \"%s\".\n", orcpy, ftcpy); + else + printf("Try again: expected \"%s\", got \"%s\".\n", orcpy, ftcpy); + free(orcpy); + free(ftcpy); +} + +void test_substr(void) +{ + printf("\n\n=========== TESTING SUBSTR ============\n\n"); + + char srcstr[20] = "Hello World!"; + char *substr; + + substr = ft_substr(srcstr, 6, 20); + if (!strcmp(srcstr + 6, substr)) + printf("OK: expected \"%s\", got \"%s\".\n", srcstr + 6, substr); + else + printf("Try again: expected \"%s\", got \"%s\".\n", srcstr + 6, substr); + free(substr); + + + substr = ft_substr(srcstr, 0, 20); + if (!strcmp(srcstr, substr)) + printf("OK: expected \"%s\", got \"%s\".\n", srcstr, substr); + else + printf("Try again: expected \"%s\", got \"%s\".\n", srcstr, substr); + free(substr); + + substr = ft_substr(srcstr, 7, 1); + if (substr[0] == srcstr[7] && substr[1] == '\0') + printf("OK: expected \"%c\", got \"%s\".\n", srcstr[7], substr); + else + printf("Try again: expected \"%c\", got \"%s\".\n", srcstr[7], substr); + free(substr); + + + substr = ft_substr("", 7, 5); + if (!strcmp(substr, "")) + printf("OK: expected \"%s\", got \"%s\".\n", "", substr); + else + printf("Try again: expected \"%s\", got \"%s\".\n", "", substr); + free(substr); + + substr = ft_substr("Hello", 2, 0); + if (!strcmp(substr, "")) + printf("OK: expected \"%s\", got \"%s\".\n", "", substr); + else + printf("Try again: expected \"%s\", got \"%s\".\n", "", substr); + free(substr); + + substr = ft_substr("Hello", 15, 5); + if (!strcmp(substr, "")) + printf("OK: expected \"%s\", got \"%s\".\n", "", substr); + else + printf("Try again: expected \"%s\", got \"%s\".\n", "", substr); + free(substr); + + substr = ft_substr("", 0, 5); + if (!strcmp(substr, "")) + printf("OK: expected \"%s\", got \"%s\".\n", "", substr); + else + printf("Try again: expected \"%s\", got \"%s\".\n", "", substr); + free(substr); +} + +void test_strjoin(void) +{ + printf("\n\n=========== TESTING STRJOIN ============\n\n"); + + + char join0[100] = ""; + char join1[100] = "Coucou!"; + char join2[100] = " comment va la vie?"; + char *res0 = NULL; + char *res1; + res1 = ft_strjoin(join1, join2); + res0 = strcat(join1, join2); + if (!strcmp(res0, res1)) + printf("OK: expected \"%s\", got \"%s\".\n", res0, res1); + else + printf("Try again: expected \"%s\", got \"%s\".\n", res0, res1); + free(res1); + + strcpy(join1, "Coucou!"); + res1 = ft_strjoin(join0, join1); + res0 = strcat(join0, join1); + if (!strcmp(res0, res1)) + printf("OK: expected \"%s\", got \"%s\".\n", res0, res1); + else + printf("Try again: expected \"%s\", got \"%s\".\n", res0, res1); + free(res1); + + strcpy(join1, " comment va la vie?"); + strcpy(join2, ""); + res1 = ft_strjoin(join1, join2); + res0 = strcat(join1, join2); + if (!strcmp(res0, res1)) + printf("OK: expected \"%s\", got \"%s\".\n", res0, res1); + else + printf("Try again: expected \"%s\", got \"%s\".\n", res0, res1); + free(res1); + + strcpy(join0, ""); + strcpy(join1, ""); + res1 = ft_strjoin(join0, join1); + res0 = strcat(join0, join1); + if (!strcmp(res0, res1)) + printf("OK: expected \"%s\", got \"%s\".\n", res0, res1); + else + printf("Try again: expected \"%s\", got \"%s\".\n", res0, res1); + free(res1); +} + +void test_strtrim(void) +{ + printf("\n\n=========== TESTING STRTRIM ============\n\n"); + + char *trimmed; + + trimmed = ft_strtrim("/......../.hello./////...", "./"); + if (!strcmp("hello", trimmed)) + printf("OK: expected \"%s\", got \"%s\".\n", "hello", trimmed); + else + printf("Try again: expected \"%s\", got \"%s\".\n", "hello", trimmed); + free(trimmed); + + trimmed = ft_strtrim("", "abcd"); + if (!strcmp("", trimmed)) + printf("OK: expected \"%s\", got \"%s\".\n", "", trimmed); + else + printf("Try again: expected \"%s\", got \"%s\".\n", "", trimmed); + free(trimmed); + + trimmed = ft_strtrim("hello", ""); + if (!strcmp("hello", trimmed)) + printf("OK: expected \"%s\", got \"%s\".\n", "hello", trimmed); + else + printf("Try again: expected \"%s\", got \"%s\".\n", "hello", trimmed); + free(trimmed); + + trimmed = ft_strtrim("hello", "l"); + if (!strcmp("hello", trimmed)) + printf("OK: expected \"%s\", got \"%s\".\n", "hello", trimmed); + else + printf("Try again: expected \"%s\", got \"%s\".\n", "hello", trimmed); + free(trimmed); + + trimmed = ft_strtrim("hello", "xyz"); + if (!strcmp("hello", trimmed)) + printf("OK: expected \"%s\", got \"%s\".\n", "hello", trimmed); + else + printf("Try again: expected \"%s\", got \"%s\".\n", "hello", trimmed); + free(trimmed); + + trimmed = ft_strtrim("llllllhellolllllll", "l"); + if (!strcmp("hello", trimmed)) + printf("OK: expected \"%s\", got \"%s\".\n", "hello", trimmed); + else + printf("Try again: expected \"%s\", got \"%s\".\n", "hello", trimmed); + free(trimmed); + + trimmed = ft_strtrim("llllllhellolllllll", "helo"); + if (!strcmp("", trimmed)) + printf("OK: expected \"%s\", got \"%s\".\n", "", trimmed); + else + printf("Try again: expected \"%s\", got \"%s\".\n", "", trimmed); + free(trimmed); + + trimmed = ft_strtrim("llllllhello/hilllllll", "helo"); + if (!strcmp("/hi", trimmed)) + printf("OK: expected \"%s\", got \"%s\".\n", "/hi", trimmed); + else + printf("Try again: expected \"%s\", got \"%s\".\n", "/hi", trimmed); + free(trimmed); +} + +void test_split(void) +{ + printf("\n\n=========== TESTING SPLIT ============\n\n"); + char **tab; + unsigned int i; + char s0[50] = "split "; + char s1[50] = " split this for me !"; + char s2[50] = "split this for me !"; + char s3[50] = " split this for me ! "; + + + printf("---------- TEST 1 ----------\n"); + i = 0; + tab = ft_split(s0, ' '); + printf("Test string : \"%s\".\n\n", s0); + if (!tab[0]) + printf("Try again.\n"); + while (tab[i]) + { + printf("Tab [%d] : \"%s\".\n", i, tab[i]); + i++; + } + i = 0; + while (tab[i]) + { + free(tab[i]); + i++; + } + free(tab); + + printf("\n---------- TEST 2 ----------\n"); + i = 0; + tab = ft_split(s1, ' '); + printf("Test string : \"%s\".\n\n", s1); + if (!tab[0]) + printf("Try again.\n"); + while (tab[i]) + { + printf("Tab [%d] : \"%s\".\n", i, tab[i]); + i++; + } + i = 0; + while (tab[i]) + { + free(tab[i]); + i++; + } + free(tab); + + printf("\n---------- TEST 3 ----------\n"); + i = 0; + tab = ft_split(s2, ' '); + printf("Test string : \"%s\".\n\n", s2); + if (!tab[0]) + printf("Try again.\n"); + while (tab[i]) + { + printf("Tab [%d] : \"%s\".\n", i, tab[i]); + i++; + } + i = 0; + while (tab[i]) + { + free(tab[i]); + i++; + } + free(tab); + + printf("\n---------- TEST 4 ----------\n"); + i = 0; + tab = ft_split(s3, ' '); + printf("Test string : \"%s\".\n\n", s3); + if (!tab[0]) + printf("Try again.\n"); + while (tab[i]) + { + printf("Tab [%d] : \"%s\".\n", i, tab[i]); + i++; + } + i = 0; + while (tab[i]) + { + free(tab[i]); + i++; + } + free(tab); + + printf("\n---------- TEST 5 ----------\n"); + i = 0; + tab = ft_split("", ' '); + printf("Test string : \"%s\".\n\n", ""); + if (!tab[0]) + printf("Ok: expected null, got %s.\n", tab[0]); + while (tab[i]) + { + printf("Tab [%d] : \"%s\".\n", i, tab[i]); + i++; + } + i = 0; + while (tab[i]) + { + free(tab[i]); + i++; + } + free(tab); + + printf("\n---------- TEST 6 ----------\n"); + i = 0; + tab = ft_split("split", '\0'); + printf("Test string : \"%s\".\n\n", "split"); + if (!tab[0]) + printf("Try again.\n"); + while (tab[i]) + { + printf("Tab [%d] : \"%s\".\n", i, tab[i]); + i++; + } + i = 0; + while (tab[i]) + { + free(tab[i]); + i++; + } + free(tab); + + printf("\n---------- TEST 7 ----------\n"); + i = 0; + tab = ft_split("\0aa\0bbb", '\0'); + printf("Test string : \"%s\".\n\n", "\\0aa\\0bbb"); + if (!tab[0]) + printf("Ok: expected null, got %s.\n", tab[0]); + while (tab[i]) + { + printf("Tab [%d] : \"%s\".\n", i, tab[i]); + i++; + } + i = 0; + while (tab[i]) + { + free(tab[i]); + i++; + } + free(tab); + + printf("\n---------- TEST 8 ----------\n"); + i = 0; + tab = ft_split(" ", ' '); + printf("Test string : \"%s\".\n\n", " "); + if (!tab[0]) + printf("Ok: expected null, got %s.\n", tab[0]); + while (tab[i]) + { + printf("Tab [%d] : \"%s\".\n", i, tab[i]); + i++; + } + i = 0; + while (tab[i]) + { + free(tab[i]); + i++; + } + free(tab); + + printf("\n---------- TEST 9 ----------\n"); + i = 0; + tab = ft_split("lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse", ' '); + printf("Test string : \"%s\".\n\n", "lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse"); + if (!tab[0]) + printf("Try again.\n"); + while (tab[i]) + { + printf("Tab [%d] : \"%s\".\n", i, tab[i]); + i++; + } + i = 0; + while (tab[i]) + { + free(tab[i]); + i++; + } + free(tab); + + printf("\n---------- TEST 10 ----------\n"); + i = 0; + tab = ft_split("lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultricies diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi.", 'i'); + printf("Test string : \"%s\" split at 'i'.\n\n", "lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultricies diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi."); + if (!tab[0]) + printf("Try again.\n"); + while (tab[i]) + { + printf("Tab [%d] : \"%s\".\n", i, tab[i]); + i++; + } + i = 0; + while (tab[i]) + { + free(tab[i]); + i++; + } + free(tab); + + printf("\n---------- TEST 11 ----------\n"); + i = 0; + tab = ft_split("lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultricies diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi.", 'z'); + printf("Test string : \"%s\" split at 'z'.\n\n", "lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultricies diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi."); + if (!tab[0]) + printf("Try again.\n"); + while (tab[i]) + { + printf("Tab [%d] : \"%s\".\n", i, tab[i]); + i++; + } + i = 0; + while (tab[i]) + { + free(tab[i]); + i++; + } + free(tab); +} + +void test_itoa(void) +{ + printf("\n\n=========== TESTING ITOA ============\n\n"); + + int n; + + n = 0; + if (!strcmp("0", ft_itoa(n))) + printf("OK: expected \"%d\", got \"%s\".\n", n, ft_itoa(n)); + else + printf("Try again: expected \"%d\", got \"%s\".\n", n, ft_itoa(n)); + + n = 123456789; + if (!strcmp("123456789", ft_itoa(n))) + printf("OK: expected \"%d\", got \"%s\".\n", n, ft_itoa(n)); + else + printf("Try again: expected \"%d\", got \"%s\".\n", n, ft_itoa(n)); + + n = -42; + if (!strcmp("-42", ft_itoa(n))) + printf("OK: expected \"%d\", got \"%s\".\n", n, ft_itoa(n)); + else + printf("Try again: expected \"%d\", got \"%s\".\n", n, ft_itoa(n)); + + n = -2147483648; + if (!strcmp("-2147483648", ft_itoa(n))) + printf("OK: expected \"%d\", got \"%s\".\n", n, ft_itoa(n)); + else + printf("Try again: expected \"%d\", got \"%s\".\n", n, ft_itoa(n)); +} + +char test_strmapi_toupper(unsigned int i, char c) +{ + i--; + return (ft_toupper(c)); +} + +char test_strmapi_tolower(unsigned int i, char c) +{ + i--; + return (ft_tolower(c)); +} + +void test_strmapi(void) +{ + printf("\n\n=========== TESTING STRMAPI ============\n\n"); + + printf("\"hello!\" : \"%s\"\n", ft_strmapi("HELLO!", test_strmapi_tolower)); + printf("\"BOOYA!\" : \"%s\"\n", ft_strmapi("booya!", test_strmapi_toupper)); +} + +void test_striteri_print(unsigned int i, char *c) +{ + i--; + write(1, c, 1); +} + +void test_striteri(void) +{ + printf("\n\n=========== TESTING STRITERI ============\n\n"); + + ft_putstr("\"Hello!\" : \""); + ft_striteri("Hello!", test_striteri_print); + ft_putstr("\"\n"); + ft_putstr("\"BOOYA!\" : \""); + ft_striteri("BOOYA!", test_striteri_print); + ft_putstr("\"\n"); +} + +void test_putchar_fd(void) +{ + printf("\n\n=========== TESTING PUTCHAR_FD ============\n\n"); + + ft_putchar_fd('x', 1); + int fd = open("testing/testputchar.txt", O_WRONLY | O_CREAT, 0777); + ft_putchar_fd('x', fd); + printf("\nCheck /testing/testputchar.txt file. Should have 'x'.\n"); + close(fd); +} + +void test_putstr_fd(void) +{ + printf("\n\n=========== TESTING PUTSTR_FD ============\n\n"); + + ft_putstr_fd("Hello World!", 1); + int fd0 = open("testing/testputstr.txt", O_WRONLY | O_CREAT, 0777); + ft_putstr_fd("Hello World!", fd0); + printf("\nCheck /testing/testputstr.txt file. Should have \"Hello World!\".\n"); + close(fd0); +} + +void test_putendl_fd(void) +{ + printf("\n\n=========== TESTING PUTENDL_FD ============\n\n"); + + ft_putendl_fd("Hello World!", 1); + int fd1 = open("testing/testputendl.txt", O_WRONLY | O_CREAT, 0777); + ft_putendl_fd("Hello World!", fd1); + printf("\nCheck /testing/testputendl.txt file. Should have \"Hello World!\".\n"); + close(fd1); +} + +void test_putnbr_fd(void) +{ + printf("\n\n=========== TESTING PUTNBR_FD ============\n\n"); + + ft_putstr_fd("910\t\t: ", 1); + ft_putnbr_fd(910, 1); + ft_putstr_fd("\n123456789\t: ", 1); + ft_putnbr_fd(123456789, 1); + ft_putstr_fd("\n0\t\t: ", 1); + ft_putnbr_fd(0, 1); + ft_putstr_fd("\n-8453\t\t: ", 1); + ft_putnbr_fd(-8453, 1); + ft_putstr_fd("\n2003\t\t: ", 1); + ft_putnbr_fd(+2003, 1); + ft_putstr_fd("\n-2147483648\t: ", 1); + ft_putnbr_fd(-2147483648, 1); + ft_putstr_fd("\n", 1); + int fd2 = open("testing/testputnbr.txt", O_WRONLY | O_CREAT, 0777); + ft_putnbr_fd(910, fd2); + printf("\nCheck /testing/testputnbr.txt file. Should have \"910\".\n"); + close(fd2); +} + +/* Utility functions for list tests below */ +void ft_del(void *content) +{ + *(int*)content = 0; +} + +void *ft_m(void *content) +{ + void *newcontent; + + newcontent = malloc(sizeof(int)); + *((int*)newcontent) = *((int*)content) + 10; + return (newcontent); +} + +void ft_it(void *content) +{ + printf("%i ", *((int*)content)); +} + +void test_list_functions(void) +{ + int tab[20]; + int i; + t_list *begin; + + *tab = 0; + begin = ft_lstnew(tab); + printf("\n=========== TESTING LSTNEW ============\n\n"); + if (begin && !begin->next && begin->content && *((int*)begin->content) == 0) + printf("OK\n"); + else + printf("Try again.\n"); + + printf("\n\n=========== TESTING LSTADD_FRONT ============\n\n"); + i = 0; + while (++i < 10) + { + tab[i] = i; + ft_lstadd_front(&begin, ft_lstnew(tab + i)); + } + t_list *tmp = begin; + printf("Should print numbers from 9 to 0.\n"); + while (tmp) + { + printf("%i ", *((int*)tmp->content)); + tmp = tmp->next; + } + + printf("\n\n=========== TESTING LSTSIZE ============\n\n"); + if (ft_lstsize(begin) == 10) + printf("OK: expected %d, got %d.\n", 10, ft_lstsize(begin)); + else + printf("Try again: expected %d, got %d.\n", 10, ft_lstsize(begin)); + + printf("\n\n=========== TESTING LSTLAST ============\n\n"); + if (*((int*)(ft_lstlast(begin)->content)) == 0) + printf("OK: expected list->content to be %d, got %d.\n", 0, *((int*)(ft_lstlast(begin)->content))); + else + printf("Try again: expected list->content to be %d, got %d.\n", 0, *((int*)(ft_lstlast(begin)->content))); + + printf("\n\n=========== TESTING LSTADD_BACK ============\n\n"); + i = 0; + while (++i < 10) + { + tab[i + 10] = -i; + ft_lstadd_back(&begin, ft_lstnew(tab + i + 10)); + } + tmp = begin; + printf("Should print numbers from 9 to -9 :\n"); + while (tmp) + { + printf("%i ", *((int*)tmp->content)); + tmp = tmp->next; + } + + printf("\n\n=========== TESTING LSTDELONE ============\n\n"); + tmp = begin->next; + ft_lstdelone(begin, ft_del); + begin = tmp; + printf("Should print numbers from 8 to -9 :\n"); + while (tmp) + { + printf("%i ", *((int*)tmp->content)); + tmp = tmp->next; + } + + printf("\n\n=========== TESTING LSTITER ============\n\n"); + printf("Should print numbers from 8 to -9 :\n"); + ft_lstiter(begin, &ft_it); + + printf("\n\n=========== TESTING LSTMAP ============\n\n"); + t_list *map; + map = ft_lstmap(begin, &ft_m, &ft_del); + printf("Should print numbers from 18 to 1 :\n"); + while (map) + { + if (begin->content) + printf("%i ", *((int*)(map->content))); + map = map->next; + } + + printf("\n\n=========== TESTING LSTCLEAR ============\n\n"); + ft_lstclear(&begin, &ft_del); + tmp = begin; + if (!tmp) + printf("OK, list doesn't exist."); + else + { + printf("Try again, list isn't null."); + while (tmp) + { + printf("[%i] ", *((int*)tmp->content)); + tmp = tmp->next; + } + } + printf("\n"); +} + +int main(void) +{ +/* printf("\n\n===============================\n"); + printf( "=========== PART 1 ============\n"); + printf( "===============================\n"); + test_isalpha(); + test_isdigit(); + test_isalnum(); + test_isascii(); + test_isprint(); + test_strlen(); + test_memset(); + test_bzero(); + + test_memmove(); + test_strlcpy(); + test_strlcat(); + test_toupper(); + test_tolower(); + test_strchr(); + test_strrchr(); + test_strncmp(); + test_memchr(); + test_memcmp(); + test_strnstr(); + test_atoi(); + + printf("\n\n=========== TESTING CALLOC ============\n\n"); + printf("??? How to test ???\n"); + test_strdup(); + + printf("\n\n===============================\n"); + printf( "=========== PART 2 ============\n"); + printf( "===============================\n"); + test_substr(); + test_strjoin(); + test_strtrim(); + test_split(); + test_itoa(); + test_strmapi(); + test_striteri(); + test_putchar_fd(); + test_putstr_fd(); + test_putendl_fd(); + test_putnbr_fd(); + +*/ printf("\n\n===============================\n"); + printf( "============ BONUS ============\n"); + printf( "===============================\n"); + test_list_functions(); +}