-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils_bonus.c
61 lines (54 loc) · 1.72 KB
/
get_next_line_utils_bonus.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ribana-b <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 13:42:53 by ribana-b #+# #+# */
/* Updated: 2023/12/06 12:03:17 by ribana-b ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
int ft_strlen_gnl(const char *str)
{
int counter;
if (str == NULL)
return (0);
counter = 0;
while (str[counter] != '\0')
counter++;
return (counter);
}
int ft_strchr_gnl(char *str, int character)
{
int index;
if (str == NULL)
return (-2);
index = 0;
while (str[index] != '\0')
{
if (str[index] == character)
return (index);
index++;
}
return (-1);
}
char *ft_strjoin_gnl(char *str, char *str2)
{
char *newstr;
int counter;
int counter2;
counter = ft_strlen_gnl(str);
counter2 = ft_strlen_gnl(str2);
newstr = (char *)malloc((counter + counter2 + 1) * sizeof(char));
if (newstr == NULL)
return (NULL);
newstr[counter + counter2] = '\0';
while (counter2-- > 0)
newstr[counter + counter2] = str2[counter2];
while (counter-- > 0)
newstr[counter] = str[counter];
free(str);
return (newstr);
}