-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strrchr.c
More file actions
56 lines (51 loc) · 1.47 KB
/
ft_strrchr.c
File metadata and controls
56 lines (51 loc) · 1.47 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sde-silv <sde-silv@student.42berlin.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/09 18:45:49 by sde-silv #+# #+# */
/* Updated: 2023/06/12 15:06:59 by sde-silv ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
#include <string.h>
size_t ft_strlen(const char *s)
{
size_t len;
len = 0;
while (s[len] != '\0')
len ++;
return (len);
}
*/
char *ft_strrchr(const char *s, int c)
{
size_t len;
char *ptr;
ptr = (char *)s;
len = ft_strlen(s);
if (c == '\0')
return (ptr + len);
while (len != 0)
{
if (ptr[len] == (char)c)
return (ptr + len);
len --;
}
if (ptr[len] == (char)c)
return (ptr);
return (0);
}
/*
int main(void)
{
write (1, strrchr("HelloWorld!", 'o'), 2);
write (1, "\n", 1);
write (1, ft_strrchr("HelloWorld!", 'o'), 2);
write (1, "\n", 1);
return (0);
}
*/