-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strrchr.c
37 lines (34 loc) · 1.15 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amacarul <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/10 15:45:39 by amacarul #+# #+# */
/* Updated: 2024/09/21 18:14:42 by amacarul ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
int pos;
if (s == NULL)
return (NULL);
pos = 0;
while (*s)
{
s ++;
pos ++;
}
if (c == '\0')
return ((char *) s);
while (pos > 0)
{
if (*s == c)
return ((char *)s);
s --;
pos --;
}
return (NULL);
}