-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils_bonus.c
118 lines (107 loc) · 2.22 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
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.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sanghpar <[email protected].> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/09 17:43:22 by sanghpar #+# #+# */
/* Updated: 2020/10/22 13:00:06 by sanghpar ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
char *ft_strchr(const char *str, int n)
{
int i;
i = 0;
if (!str)
return (0);
while (str[i])
{
if (str[i] == n)
return ((char *)(str + i));
i++;
}
return (0);
}
char *ft_strdup(const char *src)
{
int i;
int count;
char *ret;
i = 0;
count = 0;
while (src[i])
{
i++;
count++;
}
ret = (char *)malloc((count + 1) * sizeof(char));
if (!ret)
return (0);
i = 0;
while (i < count)
{
ret[i] = src[i];
i++;
}
ret[i] = 0x00;
return (ret);
}
char *ft_strsub(char const *s, unsigned int start, size_t len)
{
char *sub;
size_t i;
if ((!s) || (start > ft_strlen(s)))
return (NULL);
if (!(sub = (char*)malloc(sizeof(char) * (len + 1))))
return (NULL);
i = 0;
while ((i < len) && (s[start] != 0x00))
{
sub[i] = s[start];
i++;
start++;
}
sub[i] = 0x00;
return (sub);
}
size_t ft_strlen(const char *str)
{
int i;
i = 0;
if (str == NULL)
return (0);
while (str[i])
{
i++;
}
return (i);
}
char *ft_strjoin(const char *s1, const char *s2)
{
char *joined;
size_t i;
size_t k;
size_t y;
size_t z;
i = 0;
k = 0;
y = ft_strlen(s1);
z = ft_strlen(s2);
if (!(joined = (char *)malloc((y + z + 1) * sizeof(char))))
return (NULL);
while (i < y)
{
joined[i] = s1[i];
i++;
}
while (i < y + z)
{
joined[i] = s2[k];
i++;
k++;
}
joined[i] = 0x00;
return (joined);
}