From a136a665222f8cb4f9aa166f5f03105a518b0a50 Mon Sep 17 00:00:00 2001 From: Etienne Rey-bethbeder Date: Tue, 21 Feb 2023 16:03:08 +0100 Subject: [PATCH] echo.c --- builtins/echo.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/builtins/echo.c b/builtins/echo.c index 1670a05..683b8a1 100644 --- a/builtins/echo.c +++ b/builtins/echo.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */ -/* Updated: 2023/02/21 15:38:53 by erey-bet ### ########.fr */ +/* Updated: 2023/02/21 16:02:09 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,16 +56,14 @@ char *conca(char **strings) i = -1; while (strings[++i] != NULL) len += strlen(strings[i]); - result = (char *) malloc(len * 2 + 1); + result = (char *) ft_calloc(len * 2 + 1, sizeof(char)); if (result == NULL) return NULL; - p = result; i = 0; while (strings[i] != NULL) { - ft_strncpy(p, strings[i], ft_strlen(strings[i])); - ft_strncpy(p, " ", 1); - p += strlen(strings[i]); + ft_strncpy(result + ft_strlen(result), strings[i], ft_strlen(strings[i])); + ft_strncpy(result + ft_strlen(result), " ", 1); i++; } return (result); @@ -85,8 +83,14 @@ int echo(int fd, char **strs) i++; i = check_argument(str, &check, i); while (str[i]) - ft_putchar_fd(fd, str[i++]); + ft_putchar_fd(str[i++], fd); if (!check) write(fd, "\n", 1); return (0); } + +int main(int argc, char *argv[]) +{ + echo(1, argv); + return (0); +}