diff --git a/libft.pdf b/libft.pdf index a25d360..c6489aa 100644 Binary files a/libft.pdf and b/libft.pdf differ diff --git a/srcs/part1/ft_memchr.c b/srcs/part1/ft_memchr.c index ab61ff4..6a1c359 100644 --- a/srcs/part1/ft_memchr.c +++ b/srcs/part1/ft_memchr.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/25 13:55:51 by hulamy #+# #+# */ -/* Updated: 2019/11/25 13:55:54 by hulamy ### ########.fr */ +/* Updated: 2019/12/12 21:50:32 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,27 @@ ** locate character in string and return its position */ +/* +** #include +** +** void *ft_memchr(const void *s, int c, size_t n); +** +** int main(void) +** { +** const char *str; +** +** char *pouet = "z"; +** char *lolzer = (char *)&pouet[2]; +** lolzer = "aaaaaaaaaa"; +** str = ft_memchr(pouet, 'a', 50); +** if (!str) +** printf("NULL"); +** else +** printf("%s\n", str); +** return (0); +** } +*/ + #include "libft.h" void *ft_memchr(const void *s, int c, size_t n) diff --git a/srcs/part2/ft_split.c b/srcs/part2/ft_split.c index 40d1c25..4a27b9a 100644 --- a/srcs/part2/ft_split.c +++ b/srcs/part2/ft_split.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/12 22:41:54 by hulamy #+# #+# */ +/* Updated: 2019/12/13 01:35:15 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + /* ** return an array of string with each word found in str, with c as separator */ @@ -47,16 +59,16 @@ ** char c; ** ** i = -1; -** s = "svh ile ifh oiuo"; +** s = NULL; ** c = ' '; ** str = ft_split(s, c); -** if (str) -** { +** //if (str) +** //{ ** printf("s : '%s'\n", s); ** printf("*str : '%p'\n", str[0]); ** while (str[++i]) ** printf("str[%i] : '%s'\n", i, str[i]); -** } +** //} ** return (0); ** } */ @@ -88,15 +100,25 @@ void *ft_free(char **array, int w) return (NULL); } +char **empty_s(char **empty) +{ + if (!(empty = (char **)malloc(sizeof(char *) * 1))) + return (NULL); + empty[0] = NULL; + return (empty); +} + char **ft_split(char const *s, char c) { char **array; int w; int len; - w = 0; - if (!s || !(array = (char **)malloc(sizeof(char *) * 1000 * (count(s, c) + 1)))) + if (!s) + return (empty_s(NULL)); + if (!(array = (char **)malloc(sizeof(char *) * (count(s, c) + 1)))) return (NULL); + w = 0; while (*s != '\0') { len = 0; diff --git a/srcs/part2/main.c b/srcs/part2/main.c index a30a8db..8f48030 100644 --- a/srcs/part2/main.c +++ b/srcs/part2/main.c @@ -51,6 +51,17 @@ void print_ft_strtrim(char const *s, char const *set) printf("strtrim: [%s] [%s] -> '%s'\n", s, set, ft_strtrim(s, set)); } +void print_ft_putnbr_fd(int n, int fd) +{ + write(1, "putnbr : [", 10); + ft_putnbr_fd(n, 1); + write(1, "] [", 3); + ft_putnbr_fd(fd, 1); + write(1, "] -> '", 6); + ft_putnbr_fd(n, fd); + write(1, "'\n", 2); +} + int main() { char touppercase(unsigned int, char); @@ -61,12 +72,15 @@ int main() print_ft_itoa(1); print_ft_itoa(-1218927987); print_ft_itoa(128979827); + print_ft_itoa(2147483647); + print_ft_itoa(-2147483648); + print_ft_itoa('t'); printf("\n"); print_ft_split(" dfs zfe f ez f fez ", ' '); - print_ft_split(NULL, ' '); print_ft_split(NULL, 0); + print_ft_split(NULL, ' '); print_ft_split("", 0); print_ft_split("vzevzev fze", 0); print_ft_split(" ", 0); @@ -86,6 +100,7 @@ int main() print_ft_strjoin(NULL, "fsdf"); print_ft_strjoin("", NULL); print_ft_strjoin("sdffez", NULL); + print_ft_strjoin(" ", " "); printf("\n"); @@ -115,7 +130,8 @@ int main() printf("\n"); - print_ft_strtrim(" strtrim ", "m "); + print_ft_strtrim(" stmr trim ", "m "); + print_ft_strtrim(" ", " "); print_ft_strtrim("", ""); print_ft_strtrim(NULL, ""); print_ft_strtrim("", NULL); @@ -123,5 +139,19 @@ int main() print_ft_strtrim("efzfe fzef", ""); print_ft_strtrim("efzfzelelijz", " "); print_ft_strtrim(" e f zfzelelijz ", " "); + print_ft_strtrim("cccccccccccccccccccc", "c"); + + printf("\n"); + + print_ft_putnbr_fd(52, 1); + print_ft_putnbr_fd(2147483647, 1); + print_ft_putnbr_fd(-2147483648, 1); + print_ft_putnbr_fd(0, 1); + print_ft_putnbr_fd(-1, 1); + print_ft_putnbr_fd(239847, 1); + print_ft_putnbr_fd(34625725, 1); + print_ft_putnbr_fd(-4564562, 1); + print_ft_putnbr_fd(456, 1); + print_ft_putnbr_fd(-624724536, 1); return 0; }