-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_strrchr.c
55 lines (51 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: cjackows <cjackows@student.42wolfsburg. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/08 22:25:20 by cjackows #+# #+# */
/* Updated: 2022/06/19 15:54:23 by cjackows ### ########.fr */
/* */
/* ************************************************************************** */
#include "../inc/libft.h"
/**
* @brief Function finds the last occurrence of 'c'
* (converted to a character) in string.
* The ending NULL character is considered part of the string.
* If 's' doesnt end with NULL program might crash.
* @param s String
* @param c Character that gets searched in 's'.
* @return char* Returns a pointer to the last
* occurrence of 'c' in string.
* Returns NULL if 'c' is not found.
*/
char *ft_strrchr(const char *s, int c)
{
int i;
char *ptr;
i = 0;
ptr = 0;
while (s[i])
{
if (s[i] == (char)c)
ptr = ((char *)s + i);
i++;
}
if (s[i] == (char)c)
return ((char *)s + i);
return (ptr);
}
// int main(void)
// {
// char str[] = "lol111111111111o";
// int ch = 'o';
// char *ach;
// ach = ft_strrchr(str, ch);
// if (ach == NULL)
// printf ("We didn't find it\n");
// else
// printf ("We found it on position - %ld\n", (ach-str+1));
// return (0);
// }