-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
55 lines (50 loc) · 1.42 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: brfernan <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 17:35:23 by brfernan #+# #+# */
/* Updated: 2023/11/27 13:23:04 by brfernan ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
int ft_strlen(char *str)
{
int i;
if (!str)
return (0);
i = 0;
while (str[i] && str[i] != '\n')
i++;
if (str[i] == '\n')
i++;
return (i);
}
char *ft_strjoin(char *line, char *buf)
{
char *str;
size_t i;
size_t j;
i = 0;
j = 0;
str = malloc(ft_strlen(line) + ft_strlen(buf) + 1);
if (!str)
return (free (line), NULL);
while (line && line[i])
{
str[i] = line[i];
i++;
}
while (buf && buf[j])
{
str[i++] = buf[j];
if (buf[j] == '\n')
break ;
j++;
}
str[i] = 0;
free (line);
return (str);
}