ft_strjoin: initial implementation
This commit is contained in:
parent
7d896b939c
commit
d8ec79480f
3 changed files with 49 additions and 2 deletions
5
Makefile
5
Makefile
|
|
@ -6,7 +6,7 @@
|
|||
# By: kcolin <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/14 13:43:59 by kcolin #+# #+# #
|
||||
# Updated: 2024/10/17 11:44:01 by kcolin ### ########.fr #
|
||||
# Updated: 2024/10/17 12:03:18 by kcolin ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -35,7 +35,8 @@ SOURCES = ft_isalpha.c \
|
|||
ft_atoi.c \
|
||||
ft_calloc.c \
|
||||
ft_strdup.c \
|
||||
ft_substr.c
|
||||
ft_substr.c \
|
||||
ft_strjoin.c
|
||||
OBJECTS = $(SOURCES:.c=.o)
|
||||
CC = gcc
|
||||
|
||||
|
|
|
|||
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);
|
||||
}
|
||||
*/
|
||||
1
libft.h
1
libft.h
|
|
@ -48,5 +48,6 @@ void *ft_calloc(size_t nmemb, size_t size);
|
|||
|
||||
char *ft_strdup(const char *s);
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue