libft
ft_strrchr.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* ft_strrchr.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2019/09/04 23:31:57 by unite #+# #+# */
10 /* Updated: 2020/07/16 02:42:55 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "libft.h"
15 
20 char *ft_strrchr(const char *s, int c)
21 {
22  size_t i;
23  size_t last;
24  int found;
25 
26  i = 0;
27  last = 0;
28  found = 0;
29  while (s[i])
30  {
31  if (s[i] == c)
32  {
33  last = i;
34  found = 1;
35  }
36  i++;
37  }
38  if (found)
39  return ((char *)(s + last));
40  else if (c == 0)
41  return ((char *)(s + i));
42  else
43  return (NULL);
44 }
libft.h
ft_strrchr
char * ft_strrchr(const char *s, int c)
Replicates behaviour of strrchr from libc.
Definition: ft_strrchr.c:20