From aaa10155a5089da91d79138a0090536f8e3cec36 Mon Sep 17 00:00:00 2001 From: Guy Baconniere Date: Wed, 25 Aug 2021 18:29:24 +0200 Subject: [PATCH] sync --- C_08/git/ex04/ft_stock_str.h | 25 ++++--------- C_08/git/ex04/ft_strs_to_tab.c | 64 ++++++---------------------------- C_08/git/ex04/main.c | 15 +++----- C_09/git/ex02/ft_split.c | 27 ++++++++------ C_09/git/ex02/main.c | 4 ++- C_09/git/ex02/main.sh | 2 +- 6 files changed, 42 insertions(+), 95 deletions(-) diff --git a/C_08/git/ex04/ft_stock_str.h b/C_08/git/ex04/ft_stock_str.h index 24e3d31..c35e1b9 100644 --- a/C_08/git/ex04/ft_stock_str.h +++ b/C_08/git/ex04/ft_stock_str.h @@ -1,20 +1,9 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_stock_str.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbaconni +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2021/08/25 10:17:09 by gbaconni #+# #+# */ -/* Updated: 2021/08/25 12:05:50 by gbaconni ### ########.fr */ -/* */ -/* ************************************************************************** */ -#ifndef FT_STOCK_STR_H -# define FT_STOCK_STR_H -typedef struct s_stock_str +#ifndef FT_STOCK__STR_H +# define FT_STOCK__STR_H +typedef struct s_stock_str { - int size; - char *str; - char *copy; -} t_stock_str; + int size; + char *str; + char *copy; +} t_stock_str; #endif diff --git a/C_08/git/ex04/ft_strs_to_tab.c b/C_08/git/ex04/ft_strs_to_tab.c index 6a056fc..4ebbbc1 100644 --- a/C_08/git/ex04/ft_strs_to_tab.c +++ b/C_08/git/ex04/ft_strs_to_tab.c @@ -1,64 +1,22 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* s_stock_str.c :+: :+: :+: */ +/* ft_point.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: gbaconni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2021/08/25 10:17:09 by gbaconni #+# #+# */ -/* Updated: 2021/08/25 12:05:50 by gbaconni ### ########.fr */ +/* Created: 2021/08/20 10:17:09 by gbaconni #+# #+# */ +/* Updated: 2021/08/20 12:05:50 by gbaconni ### ########.fr */ /* */ /* ************************************************************************** */ -#include -#include "ft_stock_str.h" +#ifndef FT_POINT_H +# define FT_POINT_H -int ft_strlen(char *str) +typedef struct s_point { - int i; - - i = 0; - while (str[i] != '\0') - i++; - return (i); -} - -char *ft_strcopy(char *str) -{ - char *result; - int i; - int len; - - len = ft_strlen(str); - result = (char *) malloc((len + 1) * sizeof(char)); - i = 0; - while (str[i] != '\0') - { - result[i] = str[i]; - i++; - } - result[i] = '\0'; - return (result); -} - -struct s_stock_str *ft_strs_to_tab(int ac, char **av) -{ - int i; - t_stock_str *result; - - result = (t_stock_str *) malloc((ac + 1) * sizeof(result)); - if (result == NULL) - return (NULL); - i = 0; - while (i < ac) - { - result[i].size = ft_strlen(av[i]); - result[i].str = av[i]; - result[i].copy = ft_strcopy(av[i]); - i++; - } - result[i].size = 0; - result[i].str = 0; - result[i].copy = 0; - return ((struct s_stock_str*) result); -} + int x; + int y; +} t_point; +void set_point(t_point *point); +#endif diff --git a/C_08/git/ex04/main.c b/C_08/git/ex04/main.c index c31411e..8f46011 100644 --- a/C_08/git/ex04/main.c +++ b/C_08/git/ex04/main.c @@ -10,23 +10,16 @@ /* */ /* ************************************************************************** */ -#include #include "ft_stock_str.h" struct s_stock_str *ft_strs_to_tab(int ac, char **av); -int main(int argc, char **argv) +int main(void) { t_stock_str *result; - int i; + char **av; + int ac; - (void) result; - result = ft_strs_to_tab(argc, argv); - i = 0; - while (result[i].size > 0) - { - printf("result[%d] = { size=%d, str=%s, copy=%s\n}", i, result[i].size, result[i].str, result[i].copy); - i++; - } + result = ft_strs_to_tab(ac, av) return (0); } diff --git a/C_09/git/ex02/ft_split.c b/C_09/git/ex02/ft_split.c index ae3bee8..b2e5bbb 100644 --- a/C_09/git/ex02/ft_split.c +++ b/C_09/git/ex02/ft_split.c @@ -6,13 +6,15 @@ /* By: gbaconni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/08/22 18:14:04 by gbaconni #+# #+# */ -/* Updated: 2021/08/24 13:00:34 by gbaconni ### ########.fr */ +/* Updated: 2021/08/25 18:26:47 by gbaconni ### ########.fr */ /* */ /* ************************************************************************** */ #include #include +int g_t = 0; + static char *ft_strncpy(char *dest, char *src, unsigned int n) { unsigned int i; @@ -34,7 +36,7 @@ static char *ft_strncpy(char *dest, char *src, unsigned int n) static int ft_is_charset(char c, char *charset) { - int i; + int i; i = 0; while (charset[i] != '\0') @@ -52,6 +54,8 @@ static int ft_split_len(char *str, char *charset) int size; size = 2; + if (str == NULL || charset == NULL) + return (size); p_str = str; while (*p_str != '\0') { @@ -77,24 +81,25 @@ char **ft_split(char *str, char *charset) { char **strs; char *start; - int size; int i; - size = ft_split_len(str, charset); - strs = malloc((size) * sizeof(strs)); + strs = malloc(ft_split_len(str, charset) * sizeof(strs)); + if (strs == NULL || charset == NULL || str == NULL) + return (NULL); start = str; i = 0; while (1) { - if (ft_is_charset(*str, charset) == 1 || *str == '\0') + if (ft_is_charset(*str, charset) == 1 || (*str == '\0' && g_t > 0)) { - size = str - start; - if (size > 0) - strs[i++] = ft_copy(start, size); + if (str - start > 0) + strs[i++] = ft_copy(start, str - start); start = str + 1; - if (*str == '\0') - break ; } + else + g_t++; + if (*str == '\0') + break ; str++; } strs[i] = ft_copy(str, 0); diff --git a/C_09/git/ex02/main.c b/C_09/git/ex02/main.c index 7a70667..ca44e42 100644 --- a/C_09/git/ex02/main.c +++ b/C_09/git/ex02/main.c @@ -6,7 +6,7 @@ /* By: gbaconni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/08/18 10:50:59 by gbaconni #+# #+# */ -/* Updated: 2021/08/24 11:56:21 by gbaconni ### ########.fr */ +/* Updated: 2021/08/25 14:11:02 by gbaconni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,6 +31,8 @@ int main(int argc, char *argv[]) } str = argv[1]; charset = argv[2]; + if (str[0] == '\0') + str = NULL; strs = ft_split(str, charset); printf("str=%s charset=%s (ft_split)\n", str, charset); i = 0; diff --git a/C_09/git/ex02/main.sh b/C_09/git/ex02/main.sh index a551eac..048a4ff 100755 --- a/C_09/git/ex02/main.sh +++ b/C_09/git/ex02/main.sh @@ -3,7 +3,7 @@ set -e rm -f a.out #norminette -R CheckForbiddenSourceHeader ft_*.c norminette -R CheckForbiddenSourceHeader -gcc -Wall -Wextra -Werror -o a.out *.c +gcc -Wall -Wextra -Werror -fsanitize=address -g -o a.out *.c echo $(basename $PWD): ./a.out "$@" rm -f a.out