-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strrchr.c
45 lines (38 loc) · 1.38 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: masoares <masoares@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/05 18:29:57 by masoares #+# #+# */
/* Updated: 2023/10/08 15:07:51 by masoares ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
char *ft_strrchr(const char *str, int c)
{
char *ch;
ch = (char *) str + ft_strlen((char *)str);
while (*ch != (char) c && ch != str)
{
ch--;
}
if (*ch == (char) c)
return (ch);
else
return (NULL);
}
/*
#include <stdio.h>
#include <string.h>
int main () {
int len;
const char str[] = "https://www.tutorialspoint.com";
const char ch = '.';
char *ret;
ret = strrchr(str, ch);
printf("String after |%c| is - |%s|\n", ch, ret);
return(0);
}*/