-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strrchr.c
42 lines (37 loc) · 1.34 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: estettle <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/26 10:56:03 by estettle #+# #+# */
/* Updated: 2024/10/08 17:57:43 by estettle ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/* ft_strrchr()
* locates the last occurence of the character c inside the string s and returns
* a pointer to it
* if the character isn't found, return NULL
*/
char *ft_strrchr(const char *s, int c)
{
int i;
i = ft_strlen(s);
while (i >= 0)
{
if (*(s + i) == (char)c)
return ((char *)(s + i));
i--;
}
return (NULL);
}
/*
#include <stdio.h>
int main(void)
{
char *melody = "Can. You. Hear. Me?";
printf("%s\n", ft_strrchr(melody, '\0'));
}
*/