-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils_bonus.c
72 lines (63 loc) · 1.7 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ametta <ametta@student.42roma.it> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/25 11:09:33 by ametta #+# #+# */
/* Updated: 2021/02/25 11:09:40 by ametta ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
size_t ft_strlen(const char *s)
{
size_t i;
i = 0;
while (s[i] != '\0')
i++;
return (i);
}
char *ft_strjoin(char const *s1, char const *s2)
{
size_t i;
size_t j;
char *str;
i = 0;
j = 0;
if (!(str = (char *)malloc(sizeof(char) * ft_strlen(s1) + ft_strlen(s2)
+ 1)))
return (NULL);
while (s1[i] != 0)
str[j++] = s1[i++];
i = 0;
while (s2[i] != 0)
str[j++] = s2[i++];
str[j] = s2[i];
return (str);
}
char *ft_strdup(const char *s1)
{
char *cpy;
size_t i;
i = 0;
if (!(cpy = (char*)malloc(sizeof(char) * ft_strlen(s1) + 1)))
return (NULL);
while (s1[i] != 0)
{
cpy[i] = s1[i];
i++;
}
cpy[i] = '\0';
return (cpy);
}
char *ft_strchr(const char *s, int c)
{
size_t i;
i = 0;
while (s[i] != c && s[i] != '\0')
i++;
if (s[i] == c)
return ((char*)s + i);
return (NULL);
}