-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils_bonus.c
executable file
·86 lines (75 loc) · 1.83 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ebabaogl <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/03 11:09:52 by ebabaogl #+# #+# */
/* Updated: 2024/11/03 12:24:27 by ebabaogl ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
void *ft_memset(void *b, int c, size_t len)
{
unsigned char *ptr;
ptr = (unsigned char *)b;
while (len--)
*ptr++ = (unsigned char)c;
return (b);
}
void *ft_calloc(size_t count, size_t size)
{
unsigned char *ptr;
size_t i;
ptr = malloc(size * count);
if (!ptr)
return (NULL);
i = 0;
while (i < size * count)
ptr[i++] = 0;
return (ptr);
}
size_t ft_strlen(char *s)
{
const char *c;
if (!s)
return (0);
c = s;
while (*c)
c++;
return (c - s);
}
char *ft_strchr(char *s, int c)
{
unsigned char uc;
uc = (unsigned char)c;
while (*s && *s != uc)
s++;
if (*s == uc || !uc)
return ((char *)s);
return (NULL);
}
char *ft_strjoin(char *s1, char *s2)
{
char *str;
size_t i;
size_t j;
str = ft_calloc((ft_strlen(s1) + ft_strlen(s2) + 1), sizeof(char));
if (!str || !s1 || !s2)
return (NULL);
i = 0;
while (s1[i])
{
str[i] = s1[i];
i++;
}
j = 0;
while (s2[j])
{
str[i] = s2[j];
i++;
j++;
}
return (str);
}