-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strrchr.c
40 lines (37 loc) · 1.23 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: ebassi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/11 17:05:59 by ebassi #+# #+# */
/* Updated: 2022/01/18 12:27:53 by ebassi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
int i;
int len;
char *res;
int temp_index;
char ch;
ch = c;
i = 0;
len = 0;
temp_index = -1;
while (s[len] != '\0')
len++;
while (i < len + 1)
{
if (s[i] == ch)
temp_index = i;
i++;
}
res = (char *)&s[temp_index];
if (temp_index == -1)
return (NULL);
else
return (res);
}