-
Notifications
You must be signed in to change notification settings - Fork 2
/
ft_strrchr.c
38 lines (34 loc) · 1.36 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: adiaz-lo <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/13 10:01:17 by adiaz-lo #+# #+# */
/* Updated: 2020/01/13 10:01:43 by adiaz-lo ### ########.fr */
/* */
/* ************************************************************************** */
/*
** This function returns a pointer to the first ocurrence of the character
** 'c' in the string 's'. Additionally, it locates the last occurrence of 'c'.
** For further information, please check the Standard C Library function
** 'strrchr(const char *s, int c)'.
*/
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
const char *str;
str = s;
while (*s)
s++;
if (c == 0)
return ((char *)s);
while (s >= str)
{
if (*s == c)
return ((char *)s);
s--;
}
return (0);
}