This commit is contained in:
Camille Chauvet 2023-02-21 22:13:08 +01:00
commit eb4a8ed663
3 changed files with 24 additions and 12 deletions

Binary file not shown.

BIN
builtins/.echo.c.swp Normal file

Binary file not shown.

View File

@ -6,7 +6,11 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */ /* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 13:09:08 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 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; int len;
char *result; char *str;
char *p; char *p;
int i; int i;
i = -1; i = -1;
while (strings[++i] != NULL) len = 0;
len += strlen(strings[i]); while (strs[++i] != NULL)
result = (char *) ft_calloc(len * 2 + 1, sizeof(char)); len += strlen(strs[i]) + 2;
if (result == NULL) str = (char *) ft_calloc(len + 1, sizeof(char));
if (str == NULL)
return NULL; return NULL;
i = 0; i = -1;
while (strings[i] != NULL) while (strs[++i] != NULL)
{ {
ft_strncpy(result + ft_strlen(result), strings[i], ft_strlen(strings[i])); ft_strlcat(str, strs[i], ft_strlen(str) + ft_strlen(strs[i]) + 2);
ft_strncpy(result + ft_strlen(result), " ", 1); str[ft_strlen(str)] = ' ';
i++;
} }
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); ft_putchar_fd(str[i++], fd);
if (!check) if (!check)
write(fd, "\n", 1); write(fd, "\n", 1);
free(str);
return (0); return (0);
} }
/*int main(int argc, char *argv[])
{
echo(1, argv);
return (0);
}*/