-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
88 lines (80 loc) · 2.02 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
79
80
81
82
83
84
85
86
87
88
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yuske <yuske@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/30 20:07:37 by yuske #+# #+# */
/* Updated: 2023/01/18 01:28:00 by yuske ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
// 8L
char *ft_strchr(char *str, int chr)
{
if (str != NULL)
{
while (*str != (unsigned char)chr && *str != '\0')
str++;
if (*str == (unsigned char)chr)
return ((char *)str);
}
return (NULL);
}
//6L
size_t ft_strlen(const char *str)
{
size_t len;
len = 0;
while (str != NULL && str[len] != '\0')
len += 1;
return (len);
}
//16L
char *ft_strdup(const char *str)
{
char *dup;
size_t i;
if (str == NULL)
return (NULL);
dup = (char *)malloc(sizeof(char) * ft_strlen(str) + 1);
if (!dup)
return (NULL);
i = 0;
while (str[i] != '\0')
{
dup[i] = str[i];
i++;
}
dup[i] = '\0';
return (dup);
}
//22L
char *ft_strjoin(char *str1, char *str2)
{
char *nu_str;
size_t i;
size_t j;
if (!str1)
str1 = ft_strdup("");
if (!str1 || !str2)
return (NULL);
nu_str = (char *)malloc(ft_strlen(str1) + ft_strlen(str2) + 1);
if (nu_str)
{
i = 0;
j = 0;
while (str1[j] != '\0')
nu_str[i++] = str1[j++];
j = 0;
while (str2[j] != '\0')
nu_str[i++] = str2[j++];
nu_str[i] = '\0';
}
free(str1);
return (nu_str);
}
// i = ft_strlen(str1);
// j = ft_strlen(str2);
// nu_str = strcpy(nu_str, str1);