-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
84 lines (76 loc) · 1.86 KB
/
get_next_line_utils.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
77
78
79
80
81
82
83
84
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aderison <aderison@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/10 19:38:19 by aderison #+# #+# */
/* Updated: 2024/04/13 13:49:49 by aderison ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
int ft_strlen(const char *s)
{
int i;
if (!s)
return (0);
i = 0;
while (s[i])
i++;
return (i);
}
char *ft_strjoin(char const *s1, char const *s2)
{
int size;
char *ret;
int i;
int j;
i = 0;
size = ft_strlen(s1) + ft_strlen(s2);
ret = malloc(sizeof(char) * (size + 1));
if (!ret || !s1 || !s2)
return (NULL);
while (s1[i] != 0)
{
ret[i] = s1[i];
i++;
}
j = -1;
while (s2[++j] != 0)
{
ret[i] = s2[j];
i++;
}
ret[size] = 0;
return (ret);
}
char *ft_strchr(const char *str, int charac)
{
if (!str)
return (NULL);
while (*str || (char)charac == '\0')
{
if (*str == (char)charac)
return ((char *)str);
str++;
}
if (*str == charac)
return ((char *)str);
return (NULL);
}
size_t ft_strlcpy(char *dst, const char *src, size_t size)
{
size_t i;
size_t len;
if (!dst || !src)
return (0);
i = -1;
len = ft_strlen(src);
if (!size)
return (len);
while (++i < size - 1 && src[i])
dst[i] = src[i];
dst[i] = 0;
return (len);
}