-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strrchr.c
More file actions
48 lines (40 loc) · 831 Bytes
/
Copy pathft_strrchr.c
File metadata and controls
48 lines (40 loc) · 831 Bytes
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
45
46
47
48
/*
The strrchr() function performs a similar task as strchr(), but instead of
locating the first occurrence of the character c from the beginning of the
string, strrchr() identifies the last occurrence of c by searching from the end
of the string.
*/
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
char char_c;
int i;
char_c = (char) c;
i = ft_strlen(s);
s += i;
while (i >= 0)
{
if (*s == char_c)
return ((char *)s);
i--;
s--;
}
return (NULL);
}
/*
#include <stdio.h>
#include <string.h>
int main(void)
{
char s[] = "Hello World, Walter!";
char *result;
int c = 287; // 87 == 'W'
result = ft_strrchr(s, c);
if (result == NULL)
printf("'%c' not found in '%s'.\n", c, s);
else
printf("Last occurence of '%c' found in '%s' at position %ld.\n",
c, s, result - s);
return (0);
}
*/