-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
93 lines (83 loc) · 1.87 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: masoares <masoares@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/21 19:36:28 by masoares #+# #+# */
/* Updated: 2023/10/26 19:02:48 by masoares ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
int ft_strlen(char *str)
{
int i;
i = 0;
if (str == NULL)
return (1);
while (str[i] != '\0')
i++;
return (i);
}
int search_temp(char *temp)
{
int i;
i = 0;
if (temp == NULL)
return (0);
while (temp[i] != '\n' && temp[i] != '\0')
i++;
if (temp[i] == '\n')
return (1);
return (0);
}
char *add_to_line(char *temp)
{
char *str;
int i;
i = 0;
if (!*temp)
return (NULL);
while (temp[i] != '\n' && temp[i] != '\0')
i++;
str = ft_calloc(1, (i + 2));
i = 0;
while (temp[i] != '\0')
{
if (temp[i] == '\n')
{
str[i] = '\n';
i++;
break ;
}
str[i] = temp[i];
i++;
}
str[i] = '\0';
return (str);
}
char *ft_calloc(size_t size, int n)
{
char *str;
int i;
if (n == 0)
return (NULL);
i = 0;
str = (char *) malloc (size * (n));
if (str == NULL)
return (NULL);
while (i < n)
{
str[i] = '\0';
i++;
}
return (str);
}
char *ft_freeing(char **buffer, char **temp)
{
free(*temp);
free(*buffer);
*temp = NULL;
return (NULL);
}