-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strrchr.c
44 lines (41 loc) · 1.44 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dpaluszk <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/08 13:26:51 by dpaluszk #+# #+# */
/* Updated: 2024/03/18 17:08:44 by dpaluszk ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
size_t i;
i = ft_strlen(s);
if ((char)c == '\0')
return ((char *)&s[i]);
while (i > 0)
{
i--;
if (s[i] == (char)c)
return ((char *)&s[i]);
}
return (NULL);
}
// int main()
// {
// char *word = "iyajsasda";
// int d = 'a';
// char *result = ft_strrchr(word, d);
// if(result != NULL)
// {
// printf("Character '%c' found at position: %ld\n", *result, result - word);
// }
// else
// {
// printf("Character '%c' not found.\n", d);
// }
// return (0);
// }