-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strrchr.c
More file actions
37 lines (33 loc) · 1.34 KB
/
ft_strrchr.c
File metadata and controls
37 lines (33 loc) · 1.34 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kmoutaou <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/07 12:14:02 by kmoutaou #+# #+# */
/* Updated: 2021/11/19 00:48:13 by kmoutaou ### ########.fr */
/* */
/* ************************************************************************** */
/*
ft_strrchr is a re-coded -strrchr- function from <string.h> that searches
for the last occurrence of the character c in the string pointed to
by the argument str.
*/
#include "libft.h"
char *ft_strrchr(const char *str, int c)
{
unsigned char *str0;
unsigned char *ptr;
str0 = (unsigned char *)str;
ptr = NULL;
while (*str0)
{
if (*str0 == (unsigned char)c)
ptr = str0;
str0++;
}
if (*str0 == (unsigned char)c)
return ((char *)str0);
return ((char *)ptr);
}