-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
82 lines (73 loc) · 1.73 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
70
71
72
73
74
75
76
77
78
79
80
81
82
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ahel-bah <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/05 16:27:00 by ahel-bah #+# #+# */
/* Updated: 2021/12/09 20:02:53 by ahel-bah ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
int ft_strchr(const char *s)
{
int i;
i = 0;
if (s == 0)
return (0);
while (s[i] != '\0')
{
if (s[i] == '\n')
return (1);
i++;
}
return (0);
}
size_t ft_strlen(const char *s)
{
size_t i;
i = 0;
while (s[i] != '\0')
i++;
return (i);
}
char *ft_strdup(const char *s1)
{
char *s2;
int i;
i = 0;
s2 = malloc(ft_strlen(s1) * sizeof(char) + 1);
if (s2 == 0)
return (0);
while (s1[i] != '\0')
{
s2[i] = s1[i];
i++;
}
s2[i] = '\0';
return (s2);
}
char *ft_strjoin(char *buffer, char *new)
{
char *al;
size_t i;
size_t j;
if (!buffer)
buffer = ft_strdup("");
al = malloc(ft_strlen(buffer) + ft_strlen(new) + 1);
if (al == 0)
return (0);
i = 0;
while (buffer[i] != '\0')
{
al[i] = buffer[i];
i++;
}
j = 0;
while (new[j] != '\0')
al[i++] = new[j++];
al[i] = '\0';
free(buffer);
return (al);
}