diff --git a/Makefile b/Makefile index 7a9f0b0..13e97f4 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: cchauvet next = new; } diff --git a/ft_lstadd_back.o b/ft_lstadd_back.o new file mode 100644 index 0000000..cc1d98b Binary files /dev/null and b/ft_lstadd_back.o differ diff --git a/ft_lstadd_front.c b/ft_lstadd_front.c new file mode 100644 index 0000000..b17cc46 --- /dev/null +++ b/ft_lstadd_front.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_front.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet next = *lst; + *lst = new; +} diff --git a/ft_lstadd_front.o b/ft_lstadd_front.o new file mode 100644 index 0000000..3e30764 Binary files /dev/null and b/ft_lstadd_front.o differ diff --git a/ft_lstclear.c b/ft_lstclear.c new file mode 100644 index 0000000..6d07272 --- /dev/null +++ b/ft_lstclear.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstclear.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet next; + ft_lstdelone(*lst, del); + *lst = next; + } +} diff --git a/ft_lstclear.o b/ft_lstclear.o new file mode 100644 index 0000000..2114b9e Binary files /dev/null and b/ft_lstclear.o differ diff --git a/ft_lstdelone.c b/ft_lstdelone.c new file mode 100644 index 0000000..10e5005 --- /dev/null +++ b/ft_lstdelone.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet content != NULL) + del(lst->content); + free(lst); + } +} diff --git a/ft_lstdelone.o b/ft_lstdelone.o new file mode 100644 index 0000000..e5dbd56 Binary files /dev/null and b/ft_lstdelone.o differ diff --git a/ft_lstiter.c b/ft_lstiter.c new file mode 100644 index 0000000..1a06107 --- /dev/null +++ b/ft_lstiter.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstiter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet next == NULL) + { + f(lst); + lst = lst->next; + } +} diff --git a/ft_lstiter.o b/ft_lstiter.o new file mode 100644 index 0000000..6ee55e6 Binary files /dev/null and b/ft_lstiter.o differ diff --git a/ft_lstlast.c b/ft_lstlast.c new file mode 100644 index 0000000..ba0d9d7 --- /dev/null +++ b/ft_lstlast.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstlast.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet next != NULL) + lst = lst->next; + return (lst); +} diff --git a/ft_lstlast.o b/ft_lstlast.o new file mode 100644 index 0000000..263df5d Binary files /dev/null and b/ft_lstlast.o differ diff --git a/ft_lstmap.c b/ft_lstmap.c new file mode 100644 index 0000000..2ae9995 --- /dev/null +++ b/ft_lstmap.c @@ -0,0 +1,13 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet next = NULL; + new->content = content; + return (new); +} diff --git a/ft_lstnew.o b/ft_lstnew.o new file mode 100644 index 0000000..790a09e Binary files /dev/null and b/ft_lstnew.o differ diff --git a/ft_lstsize.c b/ft_lstsize.c new file mode 100644 index 0000000..fa39de9 --- /dev/null +++ b/ft_lstsize.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstsize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet next; + } + return (count); +} diff --git a/ft_lstsize.o b/ft_lstsize.o new file mode 100644 index 0000000..87640c3 Binary files /dev/null and b/ft_lstsize.o differ diff --git a/ft_memcpy.c b/ft_memcpy.c index 1467ba9..ff412ad 100644 --- a/ft_memcpy.c +++ b/ft_memcpy.c @@ -6,7 +6,7 @@ /* By: cchauvet 9) + { + ft_putnbr_fd(n / 10, fd); + ft_putnbr_fd(n % 10, fd); + } + else + ft_putchar_fd(n + 48, fd); +} diff --git a/ft_putstr_fd.c b/ft_putstr_fd.c new file mode 100644 index 0000000..d8c87d2 --- /dev/null +++ b/ft_putstr_fd.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet max) - max = ft_strlen(str); - if (ft_strlen(dst) > max) - max = ft_strlen(dst); - i = 0; - while (i < max) - { - dst[i] = str[i]; - i++; - } - return (dst); + if (size == 0) + return (ft_strlen(src)); + len_dest = ft_strlen(dest); + if (len_dest >= size) + return (ft_strlen(src) + (size)); + return (len_dest + ft_strlcpy(dest + len_dest, src, size - len_dest)); } diff --git a/ft_strlcpy.c b/ft_strlcpy.c index c29d03d..677264b 100644 --- a/ft_strlcpy.c +++ b/ft_strlcpy.c @@ -6,24 +6,23 @@ /* By: cchauvet 0 || s[i] == c) { - if (*s == (char) c) - ret = (char *) s; - s++; + if (s[i] == c) + return ((char *) &s[i]); + i--; } - return (ret); + return (NULL); } diff --git a/ft_strteri.c b/ft_strteri.c new file mode 100644 index 0000000..c202588 --- /dev/null +++ b/ft_strteri.c @@ -0,0 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet len) + max = len; + if (start >= ft_strlen(s)) + return (ft_strdup("")); + sub = ft_strndup(s + start, max); + if (sub == NULL) + return (NULL); + return (sub); +} diff --git a/ft_tolower.c b/ft_tolower.c index 642fee9..14d83da 100644 --- a/ft_tolower.c +++ b/ft_tolower.c @@ -5,16 +5,14 @@ /* +:+ +:+ +:+ */ /* By: cchauvet = 'A' && 'Z' >= c) - return (c - 48); - return (c); + return (c - ('A' - 'a') * (c >= 'A' && 'Z' >= c)); } diff --git a/ft_toupper.c b/ft_toupper.c index 6fda229..3775f6d 100644 --- a/ft_toupper.c +++ b/ft_toupper.c @@ -6,7 +6,7 @@ /* By: cchauvet = 'a' && 'z' >= c) - return (c - 48); - return (c); + return (c + ('A' - 'a') * (c >= 'a' && 'z' >= c)); } diff --git a/libft.h b/libft.h index 9ae182c..39b4339 100644 --- a/libft.h +++ b/libft.h @@ -6,22 +6,30 @@ /* By: cchauvet # include +# include +typedef struct s_list +{ + void *content; + struct s_list *next; +} t_list; + +char *ft_strdup(const char *s); +char *ft_strndup(const char *s, size_t n); +void *ft_calloc(size_t nmemb, size_t size); int ft_isalpha(int c); int ft_isdigit(int c); int ft_isalnum(int c); int ft_isascii(int c); int ft_isprint(int c); size_t ft_strlen(const char *s); -/* todo */ void *ft_memset(void *s, int c, size_t n); void ft_bzero(void *s, size_t n); void *ft_memcpy(void *dest, const void *src, size_t n); @@ -34,8 +42,31 @@ char *ft_strchr(const char *s, int c); char *ft_strrchr(const char *s, int c); int ft_strncmp(const char *s1, const char *s2, size_t n); void *ft_memchr(const void *s, int c, size_t n); +int ft_memcmp(const void *s1, const void *s2, size_t n); void *ft_memrchr(const void *s, int c, size_t n); char *ft_strnstr(const char *big, const char *little, size_t len); int ft_atoi(const char *nptr); +char *ft_substr(const char *s, unsigned int start, size_t len); +char *ft_strjoin(const char *s1, const char *s2); +char *ft_strtrim(const char *s1, const char *set); +char *ft_itoa(int n); +char **ft_split(const char *s, char c); +char *ft_strmapi(const char *s, char (*f)(unsigned int, char)); +void ft_striteri(char *s, void (*f)(unsigned int, char*)); +void ft_putchar_fd(char c, int fd); +void ft_putstr_fd(char *s, int f); +void ft_putendl_fd(char *s, int fd); +void ft_putnbr_fd(int n, int fd); + +t_list *ft_lstnew(void *content); +void ft_lstadd_front(t_list **lst, t_list *new); +int ft_lstsize(t_list *lst); +t_list *ft_lstlast(t_list *lst); +void ft_lstadd_back(t_list **lst, t_list *new); +void ft_lstdelone(t_list *lst, void (*del)(void *)); +void ft_lstclear(t_list **lst, void (*del)(void *)); +void ft_lstiter(t_list *lst, void (*f)(void *)); +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)); + #endif diff --git a/main.c b/main.c new file mode 100644 index 0000000..c652ae1 --- /dev/null +++ b/main.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include "libft.h" + +int main(int argc, char **argv) +{ + char **splitted; + + if (argc < 2) + return (1); + splitted = ft_split(argv[1], argv[2][0]); + while (*splitted != NULL) + { + puts(*splitted); + free(*splitted); + splitted++; + } + return (0); +}