-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils_bonus.c
77 lines (68 loc) · 1.66 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bregneau <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/08 14:22:09 by bregneau #+# #+# */
/* Updated: 2021/12/08 15:54:44 by bregneau ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
size_t ft_strlen(const char *s)
{
size_t len;
len = 0;
while (s[len])
len++;
return (len);
}
char *ft_strchr(const char *s, int c)
{
size_t i;
size_t len;
i = 0;
len = ft_strlen(s);
while (i <= len)
{
if (s[i] == (unsigned char)c)
return ((char *)s + i);
i++;
}
return (NULL);
}
char *ft_strcpy(char *dst, const char *src)
{
size_t i;
i = 0;
if (!src)
return (dst);
while (src[i])
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
return (dst);
}
char *ft_strndup(const char *s1, size_t n)
{
size_t size;
size_t i;
char *dst;
size = ft_strlen(s1);
if (size > n)
size = n;
dst = malloc((size + 1) * sizeof(char));
if (!dst)
return (NULL);
i = 0;
while (i < size)
{
dst[i] = s1[i];
i++;
}
dst[i] = '\0';
return (dst);
}