-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
77 lines (69 loc) · 2.09 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ybayed <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/08 14:12:32 by ybayed #+# #+# */
/* Updated: 2023/03/25 01:19:18 by ybayed ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
char *norminette_25(char *static_buffer)
{
static_buffer = (char *)malloc(1 * sizeof(char));
static_buffer[0] = '\0';
return (static_buffer);
}
char *ft_strjoin(char *static_buffer, char *buffer)
{
size_t i;
size_t j;
size_t len;
char *str;
i = -1;
j = 0;
if (!static_buffer)
static_buffer = norminette_25(static_buffer);
if (!static_buffer || !buffer)
return (NULL);
len = (ft_strlen(static_buffer) + ft_strlen(buffer)) + 1;
str = malloc(sizeof(char) * len);
if (str == NULL)
return (NULL);
if (static_buffer)
while (static_buffer[++i] != '\0')
str[i] = static_buffer[i];
while (buffer[j] != '\0')
str[i++] = buffer[j++];
str[ft_strlen(static_buffer) + ft_strlen(buffer)] = '\0';
free(static_buffer);
return (str);
}
size_t ft_strlen(char *static_buffer)
{
size_t i;
if (!static_buffer)
return (0);
i = 0;
while (static_buffer[i] != '\0')
i++;
return (i);
}
char *ft_strchr(char *static_buffer, int n)
{
int i;
i = 0;
if (!static_buffer)
return (0);
if (n == '\0')
return ((char *)&static_buffer[ft_strlen(static_buffer)]);
while (static_buffer[i] != '\0')
{
if (static_buffer[i] == (char) n)
return ((char *)&static_buffer[i]);
i++;
}
return (0);
}