-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strrchr.c
40 lines (36 loc) · 1.22 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
36
37
38
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lpicoli- < lpicoli-@student.42porto.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/08 12:07:52 by lpicoli- #+# #+# */
/* Updated: 2022/11/17 22:47:58 by lpicoli- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
int i;
i = 0;
while (*s != '\0')
{
s++;
i++;
}
if (c == '\0')
return ((char *)s);
while (--i >= 0)
{
s--;
if (*s == c)
return ((char *)s);
}
return (0);
}
/*int main()
{
printf("FAKE: %s\n", ft_strrchr("hello", 'l'));
printf("ORIGINAL: %s\n", strrchr("hello", 'l'));
}*/