-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils_bonus.c
83 lines (73 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adi-stef <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/05 14:08:42 by adi-stef #+# #+# */
/* Updated: 2023/02/06 09:14:23 by adi-stef ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
char *ft_first_str(char *buff)
{
char *str;
int i;
int len;
int j;
len = ft_getnl(buff);
str = (char *) malloc((len + 1) * sizeof (char));
if (!str)
return (0);
str[len] = 0;
i = 0;
j = 0;
while (i < len)
str[i++] = buff[j++];
ft_memmove(buff, buff + j);
return (str);
}
void ft_memmove(char *dst, char *src)
{
size_t i;
i = 0;
while (*src && i <= BUFFER_SIZE)
{
dst[i++] = *src;
src++;
}
while (dst[i] && i <= BUFFER_SIZE)
dst[i++] = 0;
}
int ft_getnl(char *str)
{
int i;
i = 0;
while (str[i] && str[i] != 10)
i++;
if (str[i] == 10)
i++;
return (i);
}
int ft_nlinstr(char *str)
{
int i;
i = -1;
while (str[++i])
{
if (str[i] == 10)
return (1);
}
if (str[i] == 10)
return (1);
return (0);
}
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}