-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
78 lines (71 loc) · 1.84 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fvon-nag <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/06 09:52:22 by fvon-nag #+# #+# */
/* Updated: 2023/01/07 10:05:25 by fvon-nag ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int ft_strlen(const char *str)
{
int i;
i = 0;
if (!str)
return (0x0);
while (str[i] != '\0')
{
i++;
}
return (i);
}
char *ft_strchr(char *c, int i)
{
int j;
j = 0;
if (!c)
return (NULL);
if (i == '\0')
return ((char *)&c[ft_strlen(c)]);
while (c[j] != '\0')
{
if (c[j] == (char) i)
return ((char *)&c[j]);
j++;
}
return (NULL);
}
char *ft_strjoin(char *str, char *buff)
{
size_t i;
size_t j;
char *nstr;
if (!str)
{
str = (char *)malloc(1 * sizeof(char));
str[0] = '\0';
}
if (!str || !buff)
return (NULL);
nstr = malloc(sizeof(char) * ((ft_strlen(str) + ft_strlen(buff)) + 1));
if (nstr == NULL)
return (NULL);
i = -1;
j = 0;
if (str)
while (str[++i] != '\0')
nstr[i] = str[i];
while (buff[j] != '\0')
nstr[i++] = buff[j++];
nstr[ft_strlen(str) + ft_strlen(buff)] = '\0';
free(str);
return (nstr);
}