This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
get_next_line_utils.c
99 lines (89 loc) · 2.01 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
89
90
91
92
93
94
95
96
97
98
99
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dground <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/16 15:54:59 by dground #+# #+# */
/* Updated: 2021/10/19 13:56:08 by dground ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strlen(char *str)
{
int i;
i = 0;
if (!str)
return (0);
while (str[i] != '\0')
{
i++;
}
return (i);
}
char *ft_strchr(char *s, int c)
{
if (!s)
return (0);
if ((char)c == '\0')
return ((char *)s);
while (*s != '\0')
{
if (*s == (char)c)
return ((char *)s);
s++;
}
return (0);
}
char *ft_strcpy(char *str, char *leftover)
{
int i;
i = 0;
while (leftover[i] != '\0')
{
str[i] = leftover[i];
i++;
}
str[i] = '\0';
return (str);
}
char *ft_strcat(char *str, char *buff)
{
int i;
int j;
i = 0;
j = 0;
while (str[i] != '\0')
{
i++;
}
while (buff[j] != '\0')
{
str[i + j] = buff[j];
j++;
}
str[i + j] = '\0';
return (str);
}
char *ft_strjoin(char *leftover, char *buff)
{
char *str;
size_t length;
if (!leftover)
{
leftover = (char *)malloc(sizeof(char) * 1);
leftover[0] = '\0';
}
if (!leftover || !buff)
return (NULL);
length = ft_strlen(leftover) + ft_strlen(buff) + 1;
str = (char *)malloc(sizeof(char) * length);
if (str == NULL)
return (NULL);
if (leftover)
ft_strcpy(str, leftover);
ft_strcat(str, buff);
free(leftover);
return (str);
}