-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibft_c.c
80 lines (70 loc) · 1.91 KB
/
libft_c.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft_c.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: snara <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/15 14:30:51 by snara #+# #+# */
/* Updated: 2021/01/20 02:56:39 by snara ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
char *ft_strc(const char *s, int c)
{
while (s && *s)
{
if (c && *s == (char)c)
return ((char *)s);
else if (*s == '\0')
return (NULL);
s++;
}
return (NULL);
}
char *ft_strnc(const char *str, const char *find, size_t n, char c)
{
size_t i;
size_t j;
i = 0;
while (str && find)
{
j = 0;
while (str[i] && str[i] == c)
i++;
while (find[j] && str[i + j] && str[i + j] == find[j]
&& str[i + j] != c && j < n)
j++;
if (str[i + j] == c)
return ((char *)&str[i]);
else if (!str[i])
return (NULL);
while (str[i] && str[i] != c)
i++;
}
return (NULL);
}
int ft_putcn(const char c, int n, int fd)
{
int r;
r = 0;
while (0 < n--)
r += write(fd, &c, 1);
return (r);
}
int ft_putsn(const char *s, int n, int fd)
{
int i;
i = 0;
while (s && (i < n || n < 0) && s[i])
i++;
return (fd >= 0 && s ? write(fd, s, i) : i);
}
int ft_putsc(const char *s, const char c, int fd)
{
int i;
i = 0;
while (s && s[i] != c && s[i])
i++;
return (fd >= 0 && s ? write(fd, s, i) : i);
}