ft_strjoin: initial implementation
This commit is contained in:
parent
7d896b939c
commit
d8ec79480f
3 changed files with 49 additions and 2 deletions
45
ft_strjoin.c
Normal file
45
ft_strjoin.c
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/17 12:03:29 by kcolin #+# #+# */
|
||||
/* Updated: 2024/10/17 12:09:03 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
char *ft_strjoin(char const *s1, char const *s2)
|
||||
{
|
||||
char *out;
|
||||
size_t len;
|
||||
|
||||
len = ft_strlen(s1) + ft_strlen(s2) + 1;
|
||||
out = malloc(len);
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
ft_strlcpy(out, s1, len);
|
||||
ft_strlcat(out, s2, len);
|
||||
return (out);
|
||||
}
|
||||
|
||||
/*
|
||||
#include <stdio.h> // BAD
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc > 2)
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = ft_strjoin(argv[1], argv[2]);
|
||||
printf("'%s'\n", str);
|
||||
free(str);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue