-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils_bonus.c
125 lines (114 loc) · 2.45 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bsamli <bsamli@student.42istanbul.com.t +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/01 15:50:37 by bsamli #+# #+# */
/* Updated: 2022/11/01 17:47:10 by bsamli ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
int ft_strlen(char *c)
{
int i;
i = 0;
if (!c)
return (0);
while (c[i])
{
i++;
}
return (i);
}
int ft_find(char *finder)
{
int i;
i = 0;
if (!finder)
return (1);
while (finder && finder[i])
{
if (finder[i] == '\n')
return (0);
i++;
}
return (1);
}
char *ft_strjoin(char *lft_str, char *buff)
{
size_t i;
size_t j;
char *str;
if (!lft_str)
{
lft_str = malloc (sizeof(char) * 1);
lft_str[0] = '\0';
}
if (!buff)
return (0);
str = malloc (sizeof(char) * (ft_strlen(lft_str) + ft_strlen(buff) + 1));
if (!str)
return (0);
i = -1;
while (lft_str[++i] != '\0')
str[i] = lft_str[i];
j = 0;
while (buff[j] != '\0')
str[i++] = buff[j++];
str[i] = '\0';
free(lft_str);
return (str);
}
char *ft_line(char *handle_string)
{
char *ptr;
int i;
i = 0;
if (!handle_string[i])
{
return (NULL);
}
while (handle_string[i] && handle_string[i] != '\n')
i++;
ptr = malloc (sizeof(char) * (i + 2));
i = 0;
if (!ptr)
return (0);
while (handle_string[i] && handle_string[i] != '\n')
{
ptr[i] = handle_string[i];
i++;
}
if (handle_string[i] == '\n')
ptr[i++] = '\n';
ptr[i] = '\0';
return (ptr);
}
char *ft_clean(char *handle_string)
{
int i;
int j;
char *ptr;
i = 0;
j = 0;
while (handle_string[i] && handle_string[i] != '\n')
i++;
if (!handle_string[i])
{
free(handle_string);
return (0);
}
ptr = malloc (sizeof(char) * (ft_strlen(handle_string) - i + 1));
i++;
while (handle_string[i])
{
ptr[j] = handle_string[i];
i++;
j++;
}
ptr[j] = '\0';
free(handle_string);
return (ptr);
}