-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
69 lines (62 loc) · 1.68 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: fatkeski <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/23 19:23:47 by fatkeski #+# #+# */
/* Updated: 2023/12/25 19:54:55 by fatkeski ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t gnl_strlen(const char *s)
{
int i;
i = 0;
while (s[i] != '\0')
{
i++;
}
return (i);
}
char *gnl_strdup(char *arr)
{
size_t i;
char *new_line;
new_line = (char *)malloc(sizeof(char) * (gnl_strlen(arr) + 1));
if (new_line == 0)
return (0);
i = 0;
while (arr[i] != '\0')
{
new_line[i] = arr[i];
i++;
}
new_line[i] = '\0';
return (new_line);
}
char *gnl_strjoin(char *arr, char *buff)
{
char *new_arr;
size_t i;
size_t j;
if (arr == 0)
arr = gnl_strdup("");
new_arr = (char *)malloc(sizeof(char) * (gnl_strlen(arr) + gnl_strlen(buff)
+ 1));
if (new_arr == 0)
return (0);
i = 0;
while (arr[i] != '\0')
{
new_arr[i] = arr[i];
i++;
}
j = 0;
while (buff[j] != '\0')
new_arr[i++] = buff[j++];
new_arr[i] = '\0';
free(arr);
return (new_arr);
}