-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils1.c
74 lines (64 loc) · 1.71 KB
/
utils1.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rrangwan <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/25 09:05:53 by rrangwan #+# #+# */
/* Updated: 2022/04/25 09:54:53 by rrangwan ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}
void ft_putstr_fd(char *s, int fd)
{
int i;
if (!s)
return ;
i = 0;
while (s[i])
{
ft_putchar_fd(s[i], fd);
i++;
}
}
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
char *ft_strchr(const char *s, int c)
{
unsigned char a;
unsigned int i;
a = (unsigned char)c;
i = 0;
while (s[i] != '\0')
{
if (s[i] == a)
return ((char *)(s + i));
i++;
}
if (a == '\0')
return ((char *)(s + i));
return (NULL);
}
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
i = 0;
while (((unsigned char)s1[i] == (unsigned char)s2[i]) && (i < n) && \
((unsigned char)s1[i] != '\0') && ((unsigned char)s2[i] != '\0'))
i++;
if (i == n)
return (0);
else
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
}