-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathft_strrchr.c
38 lines (34 loc) · 1.35 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/04 14:36:51 by apuchill #+# #+# */
/* Updated: 2020/02/19 15:09:50 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */
/*
** LIBRARY: <string.h>
** SYNOPSIS: locate character in string (last occurence)
**
** DESCRIPTION:
** The strrchr() function locates the last occurrence of c (converted to a
** char) in the string s. If c is `\0', strrchr() locates the terminating
** `\0'.
*/
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
int i;
const char *ini;
ini = s;
i = ft_strlen(s);
s = (s + i);
while (*s != *ini && c != *s)
s--;
if (c == *s)
return ((char *)s);
return (0);
}