-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils_bonus.c
76 lines (67 loc) · 1.67 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tblanco <tblanco@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/26 11:36:00 by tblanco #+# #+# */
/* Updated: 2021/10/28 09:28:05 by tblanco ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
int ft_charinstr(char *s, char sep)
{
int i;
i = 0;
while (s && s[i])
{
if (s[i] == sep)
return (i);
i++;
}
return (-1);
}
size_t ft_strlen(char *s)
{
size_t len;
len = 0;
while (s && *s++)
len++;
return (len);
}
char *ft_strndup(char *s, size_t len)
{
char *ret;
int i;
ret = malloc(sizeof(char) * (len + 1));
if (!ret)
return (NULL);
i = 0;
while (s && *s && len--)
ret[i++] = *s++;
ret[i] = '\0';
return (ret);
}
char *ft_freejoin(char *s1, char *s2)
{
size_t len;
char *ret;
int i;
i = 0;
len = ft_strlen(s1) + ft_strlen(s2);
ret = malloc(sizeof(char) * (len + 1));
if (!ret)
return (NULL);
if (s1)
{
while (s1[i])
*ret++ = s1[i++];
free (s1);
}
if (s2)
while (*s2)
*ret++ = *s2++;
*ret = '\0';
return (ret - len);
}