diff --git a/.execution.c.swp b/.execution.c.swp deleted file mode 100644 index 04fe5fc..0000000 Binary files a/.execution.c.swp and /dev/null differ diff --git a/builtins/.echo.c.swp b/builtins/.echo.c.swp new file mode 100644 index 0000000..7361b42 Binary files /dev/null and b/builtins/.echo.c.swp differ diff --git a/builtins/echo.c b/builtins/echo.c index 3dc7c28..32c495b 100644 --- a/builtins/echo.c +++ b/builtins/echo.c @@ -6,7 +6,11 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */ +<<<<<<< HEAD /* Updated: 2023/02/21 21:45:38 by cchauvet ### ########.fr */ +======= +/* Updated: 2023/02/21 22:09:55 by erey-bet ### ########.fr */ +>>>>>>> 1fdc51a668e616de94c33d5b3b1e9cb51182916d /* */ /* ************************************************************************** */ @@ -46,27 +50,28 @@ int check_argument(char *str, int *check, int i) } -char *conca(char **strings) +char *conca(char **strs) { int len; - char *result; + char *str; char *p; int i; i = -1; - while (strings[++i] != NULL) - len += strlen(strings[i]); - result = (char *) ft_calloc(len * 2 + 1, sizeof(char)); - if (result == NULL) + len = 0; + while (strs[++i] != NULL) + len += strlen(strs[i]) + 2; + str = (char *) ft_calloc(len + 1, sizeof(char)); + if (str == NULL) return NULL; - i = 0; - while (strings[i] != NULL) + i = -1; + while (strs[++i] != NULL) { - ft_strncpy(result + ft_strlen(result), strings[i], ft_strlen(strings[i])); - ft_strncpy(result + ft_strlen(result), " ", 1); - i++; + ft_strlcat(str, strs[i], ft_strlen(str) + ft_strlen(strs[i]) + 2); + str[ft_strlen(str)] = ' '; } - return (result); + str[ft_strlen(str)] = '\0'; + return (str); } @@ -86,5 +91,12 @@ int echo(int fd, char **strs) ft_putchar_fd(str[i++], fd); if (!check) write(fd, "\n", 1); + free(str); return (0); } + +/*int main(int argc, char *argv[]) +{ + echo(1, argv); + return (0); +}*/