-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strrchr.c
41 lines (37 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
35
36
37
38
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alexmitcul <alexmitcul@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/07 00:22:10 by alexmitcul #+# #+# */
/* Updated: 2022/11/07 01:25:26 by alexmitcul ### ########.fr */
/* */
/* ************************************************************************** */
/**
* - Description:
* The strrchr() function is identical to strchr(), except it
* locates the last occurrence of c.
*
* - Return value:
* The strrchr() return a pointer to the located character,
* or NULL if the character does not appear in the string.
**/
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
unsigned char symbol;
int i;
symbol = c;
i = ft_strlen(s);
if (symbol == '\0' && s[i] == '\0')
return ((char *)&s[i]);
while (i >= 0)
{
if (s[i] == symbol)
return ((char *)&s[i]);
i--;
}
return (NULL);
}