-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strrchr.c
executable file
·33 lines (29 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mwilliam <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/06 15:46:36 by mwilliam #+# #+# */
/* Updated: 2016/11/14 08:58:32 by mwilliam ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** Locates the last occurence of c in the string s
*/
char *ft_strrchr(const char *s, int c)
{
int index;
char d;
d = c + '\0';
index = 0;
while (s[index] != '\0')
index++;
while (index >= 0 && (s[index] != d))
index--;
if (s[index] != d)
return (NULL);
return ((char *)s + index);
}