-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strrchr.c
55 lines (46 loc) · 1.78 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sperez-p <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/20 12:46:20 by sperez-p #+# #+# */
/* Updated: 2021/08/20 12:46:23 by sperez-p ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
NAME
****
ft_strrchr ---> reverse order search for a character in a string.
SYNOPSIS
********
#include "libft.h"
char *ft_strrchr(const char *str, int c);
PARAMETERS
**********
str ---> the string where to look for the character.
c ---> the character to find.
DESCRIPTION
***********
The ft_strrchr() function searches for the last ocurrence of the character 'c'
in he string pointed to by 'str'.
If it finds it, it returns a pointer to it so that we would have acces to the
rest of the string starting from that character.
RETURN VALUE
************
- If c is in str, returns a pointer to its last occurrence.
- If not, returns NULL.
*/
char *ft_strrchr(const char *s, int c)
{
size_t i;
i = ft_strlen(s);
while (i--)
{
if (*(s + i) == (char)c)
return (s + i);
}
return (NULL);
}