-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
57 lines (53 loc) · 1.46 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rabustam <rabustam@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/13 18:19:54 by rabustam #+# #+# */
/* Updated: 2023/04/20 15:23:44 by rabustam ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strchr_gnl(char *s, int c)
{
while (c > 255)
c = c - 256;
if (!s)
return (NULL);
while (*s)
{
if (*s == c)
return ((char *)(s));
s++;
}
if (*s == c)
return ((char *)(s));
return (NULL);
}
char *ft_strjoin_gnl(char *s1, char *s2)
{
char *str;
size_t i;
size_t j;
if (!s1)
{
s1 = malloc(1);
s1[0] = '\0';
}
if (!s1 || !s2)
return (NULL);
str = malloc(ft_strlen(s1) + ft_strlen(s2) + 1);
if (!str)
return (0);
i = -1;
j = 0;
while (s1[++i])
str[i] = s1[i];
while (s2[j])
str[i++] = s2[j++];
str[i] = '\0';
free(s1);
return (str);
}