-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker_help_checker.c
85 lines (77 loc) · 1.77 KB
/
checker_help_checker.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* checker_help_checker.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abadidi < abadidi@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/22 21:35:55 by abadidi #+# #+# */
/* Updated: 2022/02/23 10:10:42 by abadidi ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
char *ft_strdup(char *str)
{
char *dest;
int i;
i = 0;
if (!str || !str[0])
return (NULL);
while (str[i])
i++;
dest = (char *)malloc(i + 1);
if (!dest)
return (NULL);
i = 0;
while (str[i])
{
dest[i] = str[i];
i++;
}
dest[i] = '\0';
return (dest);
}
char *get_next_line(int fd)
{
char buff;
int n;
char h[600000];
int i;
i = 0;
if (fd < 0)
return (NULL);
n = read(fd, &buff, 1);
while (n && n > 0)
{
if (buff == '\n' || !buff)
break ;
h[i++] = buff;
n = read(fd, &buff, 1);
}
h[i] = '\0';
if (n <= 0 && i == 0)
return (NULL);
return (ft_strdup(h));
}
int ft_strcmp(const char *s1, const char *s2)
{
while ((*s1 || *s2) && (s1 && s2))
{
if (*s1 == *s2)
{
s1++;
s2++;
}
else
return ((unsigned char)*s1 - (unsigned char)*s2);
}
return (0);
}
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}