-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strrchr.c
More file actions
38 lines (35 loc) · 1.42 KB
/
ft_strrchr.c
File metadata and controls
38 lines (35 loc) · 1.42 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
35
36
37
38
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strrchr.c :+: :+: */
/* +:+ */
/* By: farodrig <farodrig@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2020/11/27 11:19:24 by farodrig #+# #+# */
/* Updated: 2021/02/28 20:51:45 by farodrig ######## odam.nl */
/* */
/* ************************************************************************** */
/*
** The strrchr() function locates the last occurrence of c (converted to a
** char) in the string pointed to by s. The terminating null character is
** considered to be part of the string; therefore if c is `\0', the functions
** locate the terminating `\0'.
*/
char *ft_strrchr(char *str, int c)
{
unsigned int i;
int last_location;
i = 0;
last_location = -1;
while (str[i] != '\0')
{
if (str[i] == c)
last_location = i;
i++;
}
if (str[i] == c)
last_location = i;
if (last_location > -1)
return (str + last_location);
return (0);
}