-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils_bonus.c
88 lines (79 loc) · 2.06 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
77
78
79
80
81
82
83
84
85
86
87
88
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: babreton <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/27 14:20:26 by babreton #+# #+# */
/* Updated: 2023/02/28 11:58:57 by babreton ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
char *ft_strdup(char *str, int len)
{
char *array;
int count;
if (!str || !len)
return (NULL);
count = -1;
array = (char *)malloc((len + 1) * sizeof(char));
while (++count < len)
array[count] = str[count];
array[count] = '\0';
return (array);
}
char *ft_strjoin(char *s1, char *s2)
{
size_t i;
int len;
char *array;
i = 0;
len = ft_strlen(s2);
if (!s1)
return (ft_strdup(s2, len));
len = len + ft_strlen(s1);
array = (char *)malloc(sizeof(char) * (len + 1));
if (!array)
return (NULL);
len = 0;
while (s1[i])
array[len++] = s1[i++];
i = 0;
while (s2[i])
array[len++] = s2[i++];
array[len] = '\0';
free(s1);
return (array);
}
int have_n(char *temp)
{
int i;
if (!temp)
return (0);
i = -1;
while (temp[++i])
if (temp[i] == 10)
return (1);
return (0);
}
char *print_line(char **temp)
{
int n_pos;
char *return_line;
char *str;
if (!*temp)
return (NULL);
str = *temp;
n_pos = 0;
while (str[n_pos] && str[n_pos] != 10)
n_pos++;
if (str[n_pos] == 10)
n_pos++;
return_line = ft_strdup(str, n_pos);
*temp = ft_strdup(str + n_pos, ft_strlen(str + n_pos));
if (str)
free(str);
str = NULL;
return (return_line);
}