maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
ft_strjoin.c
Go to the documentation of this file.
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_strjoin.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: rmikhayl <rmikhayl@student.42london.c +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2023/12/17 17:25:28 by rmikhayl #+# #+# */
9
/* Updated: 2023/12/17 17:25:28 by rmikhayl ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "
libft.h
"
14
15
/* *************************** ft_strjoin *********************************** */
16
/* Combines two text strings, 's1' and 's2', into a single longer text. */
17
/* */
18
/* In layman's terms: It's like putting two pieces of text together to make */
19
/* a longer one, creating a new text. If something's missing or there isn't */
20
/* enough space, it won't work and returns nothing. */
21
/* ************************************************************************** */
22
23
char
*
ft_strjoin
(
char
const
*s1,
char
const
*s2)
24
{
25
size_t
len;
26
char
*pt;
27
char
*result;
28
29
if
(!s1 || !s2)
30
return
(NULL);
31
len =
ft_strlen
(s1) +
ft_strlen
(s2) + 1;
32
if
(len == 0)
33
return
(NULL);
34
pt = (
char
*)malloc(
sizeof
(
char
) * len);
35
if
(!pt)
36
return
(NULL);
37
result = pt;
38
while
(*s1)
39
*pt++ = *s1++;
40
while
(*s2)
41
*pt++ = *s2++;
42
*pt =
'\0'
;
43
return
(result);
44
}
ft_strjoin
char * ft_strjoin(char const *s1, char const *s2)
Definition
ft_strjoin.c:23
libft.h
ft_strlen
size_t ft_strlen(const char *s)
Definition
ft_strlen.c:15
lib
libft
src
ft_strjoin.c
Generated by
1.9.8