-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_utils.c
58 lines (51 loc) · 957 Bytes
/
ft_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
#include "ft_connect4.h"
int ft_isspace(char map[10][9])
{
for (int j = 1; j < 7; j++)
{
if (map[1][j] == ' ')
return (NOTFULL);
}
return (FULL);
}
size_t ft_strlen(const char *s)
{
size_t i;
i = 0;
while (s[i] != '\0')
i++;
return (i);
}
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
i = 0;
if (n == 0)
return (0);
while (s1[i] == s2[i] && s1[i] != '\0' && i + 1 < n)
i++;
if ((unsigned char)s1[i] == (unsigned char)s2[i])
return (0);
else if ((unsigned char)s1[i] > (unsigned char)s2[i])
return (1);
else
return (-1);
}
char *ft_strnstr(char *haystack, const char *needle, size_t len)
{
size_t i;
size_t nlen;
i = 0;
nlen = ft_strlen(needle);
if (nlen == 0)
return ((char *)haystack);
else if (len == 0)
return (NULL);
while (haystack[i] != '\0' && i + nlen <= len)
{
if (ft_strncmp(&haystack[i], needle, nlen) == 0)
return ((char *)&haystack[i]);
i++;
}
return (NULL);
}