-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils_bonus.c
99 lines (88 loc) · 1.92 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wdelaros <wdelaros@student.42quebec.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/22 08:15:35 by wdelaros #+# #+# */
/* Updated: 2022/12/06 06:45:00 by wdelaros ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
size_t ft_strlen(const char *str)
{
size_t i;
i = 0;
if (!str)
return (0);
while (str[i] != '\0')
{
i++;
}
return (i);
}
char *ft_strjoin(char *s1, char *s2)
{
int i;
int j;
char *str;
if (!s1 || !s2)
return (free(s1), free(s2), NULL);
str = ft_calloc(ft_strlen(s1) + ft_strlen(s2) + 1, sizeof(char));
if (!str)
return (free(s1), NULL);
i = 0;
j = 0;
while (s1[i])
{
str[i] = s1[i];
i++;
}
while (s2[j])
{
str[i] = s2[j];
i++;
j++;
}
return (free(s1), str);
}
char *ft_strchr(const char *s, int c)
{
int i;
int len;
i = 0;
len = ft_strlen(s);
while (i < len + 1)
{
if (s[i] == (char)c)
{
return ((char *)s + i);
}
i++;
}
return (NULL);
}
void ft_bzero(void *s, size_t n)
{
size_t i;
char *str;
str = (char *)s;
i = 0;
if (n == 0)
return ;
while (i < n && str)
{
str[i] = 0;
i++;
}
}
void *ft_calloc(size_t count, size_t size)
{
void *str;
str = malloc(count * size);
if (!str)
return (free(str), NULL);
ft_bzero(str, count * size);
return (str);
}