-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strrchr.c
47 lines (43 loc) · 1.44 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
45
46
47
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ehenry <ehenry@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/06 20:51:20 by ehenry #+# #+# */
/* Updated: 2024/10/21 14:33:28 by ehenry ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *str, int i)
{
int j;
char *c;
j = 0;
c = NULL;
while (str[j])
{
if (str[j] == (char)i)
c = ((char *)&str[j]);
j++;
}
if (str[j] == (char)i)
return ((char *)&str[j]);
return (c);
}
/*
int main(void)
{
const char str[] = "Hello, world!";
char ch = 'o';
char *res;
res = strrchr(str,ch);
if (res != NULL)
printf ("Dernière occurence de '%c'
trouvée à la position: %ld\n", ch, res - str);
else
printf ("Le caractère '%c' n'a pas été trouvé.\n", ch);
return (0);
}
*/