-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_next_line_utils_bonus.c
More file actions
118 lines (107 loc) · 2.14 KB
/
get_next_line_utils_bonus.c
File metadata and controls
118 lines (107 loc) · 2.14 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kjungoo <kjungoo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/15 12:38:28 by kjungoo #+# #+# */
/* Updated: 2022/09/22 19:42:54 by kjungoo ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
size_t ft_strlen(char const *s)
{
size_t i;
i = 0;
while (*s)
{
i++;
s++;
}
return (i);
}
int is_with_nl(const char *s, char c)
{
size_t i;
i = 0;
while (s[i])
{
if (s[i] == c)
{
return (1);
}
i++;
}
return (0);
}
char *ft_strjoin(char const *s1, char const *s2)
{
size_t i;
size_t j;
char *str;
if (s1 == 0 || s2 == 0)
return (0);
str = (char *)malloc(ft_strlen(s1) + ft_strlen(s2) + 1);
if (str == 0)
return (0);
i = 0;
j = 0;
while (s1[i])
{
str[j++] = s1[i];
i++;
}
i = 0;
while (s2[i])
{
str[j++] = s2[i];
i++;
}
str[j] = '\0';
return (str);
}
char *ft_strdup(const char *s1)
{
char *str;
size_t i;
size_t len;
i = 0;
len = ft_strlen(s1);
str = (char *)malloc(sizeof(char) * (len + 1));
if (str == 0)
return (0);
while (i < len)
{
str[i] = s1[i];
i++;
}
str[i] = '\0';
return (str);
}
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t i;
size_t j;
char *str;
i = 0;
j = 0;
if (s == 0)
return (ft_strdup(""));
if (ft_strlen(s) <= len)
len = ft_strlen(s);
str = (char *)malloc(sizeof(char) * (len + 1));
if (str == 0)
return (0);
while (s[i])
{
if (start <= i && j < len)
{
str[j] = s[i];
j++;
}
i++;
}
str[j] = '\0';
return (str);
}