-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strrchr.c
40 lines (36 loc) · 1.51 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: dalves-p <dalves-p@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/24 18:31:06 by dalves-p #+# #+# */
/* Updated: 2021/06/29 12:16:24 by dalves-p ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** LIBRARY: <strings.h>
** DESCRIPTION:
** The strrchr() function returns a pointer to the last occurrence of the
** character c in the string s.
** It return a pointer to the matched character or NULL if the character is
** not found. The terminating null byte is considered part of the string, so
** that if c is specified as '\0', these functions return a pointer to the
** terminator.
*/
char *ft_strrchr(const char *s, int c)
{
char *ptr;
ptr = 0;
while (*s != '\0')
{
if (*s == (unsigned char)c)
ptr = (char *)s;
s++;
}
if (*s == '\0' && (unsigned char)c == '\0')
return ((char *)s);
return (ptr);
}