-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
77 lines (68 loc) · 1.77 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: ialdidi <ialdidi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/06 15:08:16 by ialdidi #+# #+# */
/* Updated: 2023/12/06 15:08:17 by ialdidi ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
int ft_strlen(const char *s)
{
int i;
i = 0;
while (s[i])
i++;
return (i);
}
char *ft_strchr(const char *s, int c)
{
char *string;
if (!s)
return (NULL);
string = (char *)s;
while (*string)
{
if (*string == (char)c)
return (string);
string++;
}
if (*string == (char)c)
return (string);
return (0);
}
char *ft_strjoin(char const *s1, char const *s2)
{
char *str;
char *str_ptr;
if (!s1 || !s2)
return (NULL);
str = (char *)malloc(ft_strlen(s1) + ft_strlen(s2) + 1);
if (!str)
return (NULL);
str_ptr = str;
while (*s1)
*str++ = *s1++;
while (*s2)
*str++ = *s2++;
*str = '\0';
return (str_ptr);
}
char *ft_strdup(const char *str)
{
char *ptr;
char *string;
if (!str)
return (ft_strdup(""));
ptr = (char *)malloc(ft_strlen(str) + 1);
if (!ptr)
return (NULL);
string = ptr;
while (*str)
*ptr++ = *str++;
*ptr = '\0';
return (string);
}