-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
80 lines (71 loc) · 1.73 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aizsak <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/19 17:26:49 by aizsak #+# #+# */
/* Updated: 2022/12/11 12:28:29 by aizsak ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strlen1(char *str)
{
int i;
i = 0;
if (!str)
return (0);
while (str[i] != '\0')
i++;
return (i);
}
int ft_strlen2(char *str)
{
int i;
i = 0;
if (!str)
return (0);
while (str[i] != '\n' && str[i] != '\0')
i++;
if (str[i] == '\n')
i++;
return (i);
}
char *ft_strjoin_gnl(char *reader, char *buff)
{
char *str;
int i;
int j;
i = 0;
j = -1;
if (!reader && !buff)
return (NULL);
str = malloc(sizeof(char) * (ft_strlen(reader) + ft_strlen(buff)) + 1);
if (!str)
return (NULL);
if (buff)
{
while (buff[i] != '\0')
{
str[i] = buff[i];
i++;
}
}
while (reader[++j] != '\0')
str[i + j] = reader[j];
if (buff)
free(buff);
str[i + j] = '\0';
return (str);
}
int check(char *str)
{
int i;
i = 0;
while (str[i] != '\0' && str[i] != '\n')
i++;
if (str[i] == '\n')
return (1);
return (0);
}