-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strrchr.c
34 lines (31 loc) · 1.19 KB
/
ft_strrchr.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: omoudni <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/23 22:42:09 by omoudni #+# #+# */
/* Updated: 2021/11/30 17:35:36 by omoudni ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
size_t s_len;
size_t ind;
const char *s_rev;
s_len = ft_strlen(s);
ind = 0;
s_rev = s + s_len - 1;
if (!c)
return ((char *)(s + s_len));
while (ind < s_len)
{
if (*s_rev == (char)c)
return ((char *)s_rev);
s_rev--;
ind++;
}
return (NULL);
}