-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strrchr.c
35 lines (32 loc) · 1.24 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: malexand <malexand@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 13:27:09 by malexand #+# #+# */
/* Updated: 2017/02/16 17:34:27 by malexand ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *str, int c)
{
int count;
int occu;
count = 0;
occu = 0;
if (str[0] == '\0')
return (NULL);
while (str[count] != '\0')
{
if (str[count] == (unsigned char)c)
occu = count;
count++;
}
if (c == '\0')
return (char *)(&str[count]);
if (occu == 0 && str[0] != c)
return (NULL);
return (char *)(&str[occu]);
}