-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strrchr.c
34 lines (30 loc) · 1.41 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bnidia <bnidia@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/12 06:49:13 by bnidia #+# #+# */
/* Updated: 2021/10/29 21:55:03 by bnidia ### ########.fr */
/* */
/* ************************************************************************** */
/* ft_strrchr
** Locates the last occurrence of 'c' in the string pointed to by 's'.
** The terminating null character is considered to be part of the string,
** therefore if 'c' is '\0', locates the terminating '\0'
** Return Value
** A pointer to the last occurrence of the character c in the string or
** NULL if the character is not found
*/
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
size_t len;
len = ft_strlen(s);
while (len && s[len] != (char)c)
len--;
if (s[len] == (char)c)
return ((char *)&s[len]);
return (NULL);
}