-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
69 lines (62 loc) · 1.76 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elmaksim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/24 13:23:23 by elmaksim #+# #+# */
/* Updated: 2024/01/24 14:59:00 by elmaksim ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strlen(const char *str)
{
size_t i;
i = 0;
while (str[i] != '\0')
i++;
return (i);
}
char *ft_strchr(const char *str, int ch)
{
int i;
i = 0;
if (!str)
return (0);
if (ch == '\0')
return ((char *)&str[ft_strlen(str)]);
while (str[i] != '\0')
{
if (str[i] == (char) ch)
return ((char *)&str[i]);
i++;
}
return (NULL);
}
char *ft_strjoin(char *str_1, char *str_2)
{
size_t i;
size_t c;
char *str;
if (!str_1)
{
str_1 = (char *)malloc(1 * sizeof(char));
if (!str_1 || !str_2)
return (NULL);
str_1[0] = '\0';
}
str = malloc((ft_strlen(str_1) + ft_strlen(str_2) + 1) * sizeof(char));
if (str == NULL)
return (NULL);
i = -1;
c = 0;
if (str_1)
while (str_1[++i] != '\0')
str[i] = str_1[i];
while (str_2[c] != '\0')
str[i++] = str_2[c++];
str[ft_strlen(str_1) + ft_strlen(str_2)] = '\0';
free(str_1);
return (str);
}