-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_next_line_utils.c
More file actions
95 lines (84 loc) · 1.84 KB
/
get_next_line_utils.c
File metadata and controls
95 lines (84 loc) · 1.84 KB
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
88
89
90
91
92
93
94
95
/* ************************************************************************** */
/* */
/* :::::::: */
/* get_next_line_utils.c :+: :+: */
/* +:+ */
/* By: anonymous <anonymous@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2020/12/04 11:40:12 by anonymous #+# #+# */
/* Updated: 2020/12/11 13:57:54 by ivork ######## odam.nl */
/* */
/* ************************************************************************** */
#include <stdlib.h>
size_t ft_strlen(const char *s)
{
size_t i;
i = 0;
while (s[i] != '\0')
i++;
return (i);
}
int ft_strchr(char *str, char c)
{
int i;
i = 0;
while (str[i] != '\0')
{
if (str[i] == c)
return (i + 1);
i++;
}
return (0);
}
char *ft_memmove(char *dest, char *src)
{
int i;
i = 0;
if (!(ft_strchr(dest, '\n')))
return (0);
while (src[i] != '\0')
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return (dest);
}
char *ft_bzero(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
str[i] = 0;
i++;
}
return (str);
}
char *ft_strcjoin(char *s1, char *s2)
{
char *newstr;
size_t i;
size_t n;
if (!s1 || !s2)
return (NULL);
newstr = (char*)malloc(ft_strlen(s1) + ft_strlen(s2) + 1);
i = 0;
n = 0;
if (newstr == NULL)
return (NULL);
while (s1[i] != '\0')
{
newstr[i] = s1[i];
i++;
}
while (s2[n] != '\0' && s2[n] != '\n')
{
newstr[i] = s2[n];
i++;
n++;
}
newstr[i] = '\0';
free(s1);
return (newstr);
}