-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strrchr.c
More file actions
34 lines (31 loc) · 1.24 KB
/
ft_strrchr.c
File metadata and controls
34 lines (31 loc) · 1.24 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pabad-ap <pabad-ap@student.42barcel> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/16 18:15:14 by pabad-ap #+# #+# */
/* Updated: 2023/09/16 18:29:49 by pabad-ap ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
int pos;
int last_ocurrence;
pos = 0;
last_ocurrence = 0;
while (s[pos])
{
if (s[pos] == (char)c)
last_ocurrence = pos;
pos ++;
}
if ((char)c == '\0')
return ((char *)(s + pos));
else if (last_ocurrence == 0 && s[0] != (char)c)
return (NULL);
else
return ((char *)(s + last_ocurrence));
}