-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils_bonus.c
87 lines (78 loc) · 1.8 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: majjig <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/16 18:17:00 by majjig #+# #+# */
/* Updated: 2021/11/16 18:39:51 by majjig ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
int ft_strlen(char *str)
{
int len;
len = 0;
if (str == NULL)
return (0);
while (*str++)
len++;
return (len);
}
char *ft_strdup(char *src)
{
char *dest;
int len;
int i;
i = 0;
len = ft_strlen(src);
dest = (char *) malloc((len + 1) * sizeof(char));
if (!dest)
return (NULL);
while (i < len)
{
dest[i] = src[i];
i++;
}
dest[i] = 0;
return (dest);
}
char *ft_strjoin(char *s1, char *s2)
{
char *str;
int total;
int i;
int j;
i = 0;
j = 0;
if (s2 == NULL)
return (s1);
total = ft_strlen(s1) + ft_strlen(s2) + 1;
str = (char *) malloc(total * sizeof(char));
if (str == NULL)
return (NULL);
while (s1[j])
str[i++] = s1[j++];
j = 0;
while (s2[j])
str[i++] = s2[j++];
str[i] = 0;
free(s1);
free(s2);
return (str);
}
int is_nl(char *s)
{
int i;
i = 0;
if (s == NULL)
return (0);
while (s[i])
{
if (s[i] == '\n')
return (1);
i++;
}
return (0);
}