-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strrchr.c
53 lines (48 loc) · 1.84 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
48
49
50
51
52
53
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mlaffita <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/15 16:42:12 by mlaffita #+# #+# */
/* Updated: 2025/02/07 11:48:01 by mlaffita ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/* **********************************************************************
La fonction strchr recherche la dernière occurrence du caractère c
(converti en char) dans la chaîne de caractères str.
Si elle trouve le caractère, elle renvoie un pointeur vers la dernière
occurrence de ce caractère dans la chaîne.
Si le caractère n'est pas trouvé, elle renvoie NULL.
*************************************************************************
*/
char *ft_strrchr(const char *s, int c)
{
const char *last = 0;
c = (unsigned char)c;
while (*s != '\0')
{
if (*s == (char)c)
last = s;
s++;
}
if (c == '\0')
return ((char *) s);
return ((char *) last);
}
/*
#include <stdio.h>
#include <string.h>
int main()
{
const char s[] = "hello world";
char *result = ft_strrchr(s, 'l');
printf("caractere trouve a la position %ld\n", result - s);
//
char *resultat = strrchr(s, 'l');
printf("caractere trouve a la position %ld\n", resultat - s);
return (0);
}
*/