-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
73 lines (64 loc) · 1.71 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ulyildiz <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 16:43:50 by ulyildiz #+# #+# */
/* Updated: 2023/11/30 13:54:34 by ulyildiz ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
size_t ft_strlen(const char *s)
{
size_t len;
if (!s)
return (0);
len = 0;
while (s[len] != '\0')
len++;
return (len);
}
void *ft_calloc(size_t count, size_t nbyte)
{
void *allc;
size_t i;
allc = malloc(count * nbyte);
if (!allc)
return (NULL);
i = 0;
while (i < count * nbyte)
((char *)allc)[i++] = '\0';
return (allc);
}
char *ft_strjoin(char const *s1, char const *s2)
{
char *s3;
size_t i;
if (!s1 || !s2)
return (NULL);
i = 0;
s3 = (char *)ft_calloc(ft_strlen(s1) + ft_strlen(s2) + 1, sizeof(char));
if (!s3)
return (NULL);
while (*s1 != '\0')
s3[i++] = *(s1++);
while (*s2 != '\0')
s3[i++] = *(s2++);
return (s3);
}
size_t check_newline(char *str)
{
size_t i;
if (!str)
return (0);
i = 0;
while (str[i] != '\0')
{
if (str[i] == '\n')
return (i + 1);
i++;
}
return (0);
}