-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
78 lines (70 loc) · 1.8 KB
/
get_next_line_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lde-alen <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/23 13:15:34 by lde-alen #+# #+# */
/* Updated: 2022/01/04 13:22:50 by lde-alen ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strlen(char *str)
{
size_t i;
i = 0;
if (!str)
return (0);
while (str[i] != '\0')
i++;
return (i);
}
char *ft_strchr(char *s, int c)
{
int i;
i = 0;
if (!s)
return (0);
if (c == '\0')
return ((char *)s + ft_strlen(s));
while (s[i] != '\0')
{
if (s[i] == (char)c)
return ((char *)s + i);
i++;
}
return (0);
}
static void ft_ini2(size_t *i, size_t *j)
{
*i = -1;
*j = 0;
}
char *ft_strjoin(char *str, char *buffer)
{
size_t i;
size_t j;
char *new;
if (!str)
{
str = (char *)malloc(sizeof(char));
str[0] = '\0';
}
if (!str || !buffer)
return (NULL);
new = malloc(sizeof(char) * (ft_strlen(str) + ft_strlen(buffer) + 1));
if (!new)
return (NULL);
ft_ini2(&i, &j);
if (str)
{
while (str[++i] != '\0')
new[i] = str[i];
}
while (buffer[j] != '\0')
new[i++] = buffer[j++];
new[ft_strlen(str) + ft_strlen(buffer)] = '\0';
free (str);
return (new);
}