-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_str2.c
91 lines (80 loc) · 1.92 KB
/
ft_str2.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
86
87
88
89
90
91
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lgillot- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/19 01:37:14 by lgillot- #+# #+# */
/* Updated: 2015/11/19 01:38:52 by lgillot- ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
#include <ft_str.h>
char *ft_strncat(char *s1, const char *s2, size_t n)
{
ft_strncpy(s1 + ft_strlen(s1), s2, n);
return (s1);
}
size_t ft_strnlen(const char *s, size_t maxlen)
{
size_t len;
len = 0;
while (*s && maxlen)
{
s++;
len++;
maxlen--;
}
return (len);
}
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t dst_size;
size_t src_size;
size_t remaining_size;
dst_size = ft_strnlen(dst, size);
src_size = ft_strlen(src);
remaining_size = size - dst_size;
dst += dst_size;
if (remaining_size > 0)
{
ft_strncpy(dst, src, remaining_size);
dst[remaining_size - 1] = '\0';
}
return (dst_size + src_size);
}
char *ft_strchr(const char *s, int c)
{
int found;
while (!(found = *s == (char)c) && *s)
{
s++;
}
if (found)
{
return ((char *)s);
}
else
{
return (NULL);
}
}
char *ft_strrchr(const char *s, int c)
{
char *found;
found = NULL;
while (*s)
{
if (*s == (char)c)
{
found = (char *)s;
}
s++;
}
if (*s == (char)c)
{
found = (char *)s;
}
return (found);
}