-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils_bonus.c
76 lines (69 loc) · 1.73 KB
/
get_next_line_utils_bonus.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: het-taja <het-taja@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/26 15:15:07 by het-taja #+# #+# */
/* Updated: 2024/03/30 18:26:11 by het-taja ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
int ft_strlen(char *str)
{
int i;
i = 0;
if (!str)
return (0);
while (str && str[i])
i++;
return (i);
}
char *ft_strjoin(char *s1, char *s2)
{
int i;
char *str;
int len1;
int len2;
str = NULL;
len1 = ft_strlen(s1);
len2 = ft_strlen(s2);
i = 0;
if (s1 || s2)
{
str = malloc(sizeof(char) * (len1 + len2) + 1);
if (!str)
return (NULL);
while (i < len1)
{
str[i] = s1[i];
i++;
}
len2 = 0;
while (i < len1 + ft_strlen(s2))
str[i++] = s2[len2++];
str[len1 + ft_strlen(s2)] = '\0';
}
return (str);
}
char *ft_strdup(char *s)
{
char *str;
size_t index;
size_t lenth;
lenth = ft_strlen(s);
index = 0;
if (!s)
return (NULL);
str = (char *)malloc(lenth + 1);
if (!str)
return (NULL);
while (index < lenth)
{
str[index] = s[index];
index++;
}
str[index] = '\0';
return (str);
}