Compare commits

...

2 Commits

Author SHA1 Message Date
Etienne Rey-bethbeder
03a2cc055c Merge branch 'master' of https://git.chauvet.pro/starnakin/minishell 2023-02-21 16:03:18 +01:00
Etienne Rey-bethbeder
a136a66522 echo.c 2023-02-21 16:03:08 +01:00

View File

@ -6,7 +6,7 @@
/* 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 #+# #+# */
/* 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; i = -1;
while (strings[++i] != NULL) while (strings[++i] != NULL)
len += strlen(strings[i]); len += strlen(strings[i]);
result = (char *) malloc(len * 2 + 1); result = (char *) ft_calloc(len * 2 + 1, sizeof(char));
if (result == NULL) if (result == NULL)
return NULL; return NULL;
p = result;
i = 0; i = 0;
while (strings[i] != NULL) while (strings[i] != NULL)
{ {
ft_strncpy(p, strings[i], ft_strlen(strings[i])); ft_strncpy(result + ft_strlen(result), strings[i], ft_strlen(strings[i]));
ft_strncpy(p, " ", 1); ft_strncpy(result + ft_strlen(result), " ", 1);
p += strlen(strings[i]);
i++; i++;
} }
return (result); return (result);
@ -85,8 +83,14 @@ int echo(int fd, char **strs)
i++; i++;
i = check_argument(str, &check, i); i = check_argument(str, &check, i);
while (str[i]) while (str[i])
ft_putchar_fd(fd, str[i++]); ft_putchar_fd(str[i++], fd);
if (!check) if (!check)
write(fd, "\n", 1); write(fd, "\n", 1);
return (0); return (0);
} }
int main(int argc, char *argv[])
{
echo(1, argv);
return (0);
}