diff --git a/.Makefile.swn b/.Makefile.swn index 8eb69b8..e91197a 100644 Binary files a/.Makefile.swn and b/.Makefile.swn differ diff --git a/Makefile b/Makefile index c0b31bb..8268051 100644 --- a/Makefile +++ b/Makefile @@ -38,14 +38,14 @@ SRCS = ft_memset.c \ ft_strchr.c \ ft_strrchr.c \ ft_strncmp.c \ - strlcpy \ #a creer + ft_strlcpy.c \ ft_strlcat.c \ ft_strnstr.c \ ft_atoi.c \ ft_strdup.c \ - calloc \ #a creer + ft_calloc.c \ \ - ft_substr.c \ #ft_substr.C + ft_substr.c \ ft_strjoin.c \ ft_strtrim.c \ #fonction un peu changee ft_strsplit.c \ #ft_split.c diff --git a/OLDsrc/str/ft_strlcat.c b/OLDsrc/str/ft_strlcat.c index 941a1d0..6917fbb 100644 --- a/OLDsrc/str/ft_strlcat.c +++ b/OLDsrc/str/ft_strlcat.c @@ -6,14 +6,85 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/11/14 21:17:22 by hulamy #+# #+# */ -/* Updated: 2019/03/25 15:22:42 by hulamy ### ########.fr */ +/* Updated: 2019/11/19 14:40:09 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ /* -** append src to sized dest and return size of final dest +** append src to sized dest and return size of final dest +** +** TESTS : */ +/* +** #include +** #include +** #include +** +** size_t ft_strlcat(char *dest, const char *src, size_t size); +** +** size_t ft_strlcat2(char *dest, char *src, size_t size); +** +** int ft_strlen(char *str) +** { +** int i; +** +** i = 0; +** while (str[i]) +** i++; +** return (i); +** } +** +** int main(int ac, char **av) +** { +** char tmp1[100]; +** char tmp2[100]; +** int i; +** +** i = atoi(av[3]); +** strcpy(tmp1, av[1]); +** strcpy(tmp2, av[2]); +** +** if (ac == 4) +** { +** printf("----strlcat: %zu - %s - %s\n", strlcat(tmp1, tmp2, i), tmp1, tmp2); +** +** strcpy(tmp1, av[1]); +** strcpy(tmp2, av[2]); +** +** printf("-ft_strlcat: %zu - %s - %s\n", ft_strlcat(tmp1, tmp2, i), tmp1, tmp2); +** +** strcpy(tmp1, av[1]); +** strcpy(tmp2, av[2]); +** +** printf("ft_strlcat2: %zu - %s - %s\n", ft_strlcat2(tmp1, tmp2, i), tmp1, tmp2); +** } +** } +** +** size_t ft_strlcat2(char *dest, char *src, size_t size) +** { +** size_t i; +** size_t dest_length; +** size_t src_length; +** +** i = 0; +** dest_length = ft_strlen(dest); +** src_length = ft_strlen(src); +** if (size > dest_length + 1) +** { +** while (i < (size - dest_length - 1)) +** { +** dest[i + dest_length] = src[i]; +** i++; +** } +** dest[dest_length + i] = '\0'; +** } +** if (size >= dest_length) +** return (dest_length + src_length); +** return (src_length + size); +** } +*/ + #include "libft.h" size_t ft_strlcat(char *dest, const char *src, size_t size) diff --git a/a.out b/a.out index ac3493e..9f2559e 100755 Binary files a/a.out and b/a.out differ diff --git a/srcs/a.out b/srcs/a.out new file mode 100755 index 0000000..b2001cc Binary files /dev/null and b/srcs/a.out differ diff --git a/srcs/ft_calloc.c b/srcs/ft_calloc.c new file mode 100644 index 0000000..19ad171 --- /dev/null +++ b/srcs/ft_calloc.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/19 14:56:09 by hulamy #+# #+# */ +/* Updated: 2019/11/19 15:21:25 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** exemple allocation for 5 integers with malloc then calloc : +** a = (int *)malloc(5 * sizeof(int)); //5*4bytes = 20 bytes +** free(a); +** a = (int *)calloc(5, sizeof(int)); +** +** allocate count * size byte of memory and +** return a pointer to the allocated memory +*/ + +#include "libft.h" + +void *ft_calloc(size_t count, size_t size) +{ + return (ft_memalloc(count * size)); +} diff --git a/srcs/ft_memalloc.c b/srcs/ft_memalloc.c new file mode 100644 index 0000000..072e7f1 --- /dev/null +++ b/srcs/ft_memalloc.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memalloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/19 15:21:44 by hulamy #+# #+# */ +/* Updated: 2019/11/19 15:23:17 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** allocate size byte of memory and return a pointer to the allocated memory +*/ + +#include "libft.h" + +void *ft_memalloc(size_t size) +{ + void *tmp; + + if (!size || !(tmp = malloc(size))) + return (NULL); + ft_bzero(tmp, size); + return (tmp); +} diff --git a/srcs/ft_strlcat.c b/srcs/ft_strlcat.c new file mode 100644 index 0000000..b381f99 --- /dev/null +++ b/srcs/ft_strlcat.c @@ -0,0 +1,109 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/19 15:09:51 by hulamy #+# #+# */ +/* Updated: 2019/11/19 15:09:54 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** append src to sized dest and return size of final dest +** +** TESTS : +*/ + +/* +** #include +** #include +** #include +** +** size_t ft_strlcat(char *dest, const char *src, size_t size); +** +** size_t ft_strlcat2(char *dest, char *src, size_t size); +** +** int ft_strlen(char *str) +** { +** int i; +** +** i = 0; +** while (str[i]) +** i++; +** return (i); +** } +** +** int main(int ac, char **av) +** { +** char tmp1[100]; +** char tmp2[100]; +** int i; +** +** i = atoi(av[3]); +** strcpy(tmp1, av[1]); +** strcpy(tmp2, av[2]); +** +** if (ac == 4) +** { +** printf("----strlcat: %zu - %s - %s\n", strlcat(tmp1, tmp2, i), tmp1, tmp2); +** +** strcpy(tmp1, av[1]); +** strcpy(tmp2, av[2]); +** +** printf("-ft_strlcat: %zu - %s - %s\n", ft_strlcat(tmp1, tmp2, i), tmp1, tmp2); +** +** strcpy(tmp1, av[1]); +** strcpy(tmp2, av[2]); +** +** printf("ft_strlcat2: %zu - %s - %s\n", ft_strlcat2(tmp1, tmp2, i), tmp1, tmp2); +** } +** } +** +** size_t ft_strlcat2(char *dest, char *src, size_t size) +** { +** size_t i; +** size_t dest_length; +** size_t src_length; +** +** i = 0; +** dest_length = ft_strlen(dest); +** src_length = ft_strlen(src); +** if (size > dest_length + 1) +** { +** while (i < (size - dest_length - 1)) +** { +** dest[i + dest_length] = src[i]; +** i++; +** } +** dest[dest_length + i] = '\0'; +** } +** if (size >= dest_length) +** return (dest_length + src_length); +** return (src_length + size); +** } +*/ + +#include "libft.h" + +size_t ft_strlcat(char *dest, const char *src, size_t size) +{ + size_t i; + size_t j; + + i = 0; + j = 0; + while (dest[i] && i < size) + i++; + while (src[j]) + { + if (j + i < size - 1 && size) + { + dest[i + j] = src[j]; + dest[i + j + 1] = '\0'; + } + j++; + } + return (i + j); +} diff --git a/srcs/ft_strlcpy.c b/srcs/ft_strlcpy.c index 5c34b75..289c870 100644 --- a/srcs/ft_strlcpy.c +++ b/srcs/ft_strlcpy.c @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/19 13:03:47 by hulamy #+# #+# */ -/* Updated: 2019/11/19 14:11:39 by hulamy ### ########.fr */ +/* Created: 2019/11/19 15:10:04 by hulamy #+# #+# */ +/* Updated: 2019/11/19 15:10:07 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/ft_strtrim.c b/srcs/ft_strtrim.c new file mode 100644 index 0000000..6767eaf --- /dev/null +++ b/srcs/ft_strtrim.c @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/19 17:26:06 by hulamy #+# #+# */ +/* Updated: 2019/11/19 18:15:32 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** create a copy of s without the firsts and lasts empty characters +*/ + +/* +** #include +** +** char *ft_strtrim(char const *s1, char const *set); +** +** int main(int ac, char **av) +** { +** if (ac == 3) +** printf("%s\n",ft_strtrim(av[1], av[2])); +** +** return (0); +** } +*/ + +#include "libft.h" + +char *ft_strtrim(char const *s1, char const *set) +{ + int len; + char *str; + (void)set; + + if (!s1) + return (NULL); + while (s1[0] && ft_strchr(set, s1[0])) + s1++; + len = ft_strlen(s1) - 1; + while (len >= 0 && ft_strchr(set, s1[len])) + len--; + len++; + if (!(str = ft_strsub(s1, 0, len))) + return (NULL); + return (str); +} + + + + + + + + + diff --git a/srcs/ft_substr.c b/srcs/ft_substr.c new file mode 100644 index 0000000..2e76ab2 --- /dev/null +++ b/srcs/ft_substr.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/19 17:20:51 by hulamy #+# #+# */ +/* Updated: 2019/11/19 17:24:10 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** create a copy of a portion of s, begining at start and of length len +*/ + +#include "libft.h" + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + char *str; + size_t i; + + if (!s) + return (NULL); + if (!(str = ft_strnew(len))) + return (NULL); + i = 0; + while (i < len) + str[i++] = s[start++]; + return (str); +}