-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strrchr.c
35 lines (32 loc) · 1.2 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
35
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mavinici <mavinici@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/15 18:00:36 by mavinici #+# #+# */
/* Updated: 2021/05/28 21:07:45 by mavinici ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
char *ft_strrchr(const char *s, int c)
{
char *s_s;
int i;
int pos;
i = 0;
pos = -1;
s_s = (char *)s;
while (s_s[i])
{
if (s_s[i] == (char)c)
pos = i;
i++;
}
if ((char)c == '\0')
return (s_s + i);
else if (pos >= 0)
return (s_s + pos);
return (NULL);
}