-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathft_strrchr.c
44 lines (39 loc) · 1.64 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: mihykim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/26 13:27:29 by mihykim #+# #+# */
/* Updated: 2020/04/03 22:07:59 by mihykim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** - Locates 'last' occurrence of 'c'(converted to a char) pointed to by 's'.
** - The terminating NULL is considered to be part of string.
** (therefore if 'c' is '', the functions locate terminating '')
** - Returns a pointer to the located character,
** or NULL if the character does not appear in the string.
*/
char *ft_strrchr(const char *s, int c)
{
int i;
i = ft_strlen(s);
while (i >= 0)
{
if (s[i] == (char)c)
return ((char *)s + i);
i--;
}
return (0);
}
/*
** line 25 : declare int type instead of size_t (so that i can be -1)
** test 5 "-s" "+Null"
** test 8 "-bonjour" "+Null"
** line 28 : change while conditino from 'i > 0' to 'i >= 0',
** to search until i = 0
** line 31 : change return value from 's' to 's + i'
*/