-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strrchr.c
More file actions
42 lines (38 loc) · 1.52 KB
/
Copy pathft_strrchr.c
File metadata and controls
42 lines (38 loc) · 1.52 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
39
40
41
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: muhozkan <muhozkan@student.42.tr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/19 16:17:46 by muhozkan #+# #+# */
/* Updated: 2022/02/25 23:34:06 by muhozkan ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *str, int c)
{
int i;
i = 0;
while (str[i])
{
i++;
}
while (i >= 0)
{
if (str[i] == c)
{
return (((char *)str) + i);
}
i--;
}
return (NULL);
}
// sagdan baslayarak istedigimiz harfi bulur ve kelimeyi döndürür
/*
int c yerine yazdığımız karakterin son göründüğü yeri belirler.
* s nin point ettiği ilk karakteri kaybetmemek için oraya b pointerını atıyoruz.
syi de s nin son elemanını point edecek şekilde atıyoruz.
* s pointerını c karakterine rastlayana kadar sondan başa doğru gezdiriyoruz.
* c yi bulduğunda point ettiği yerden itibaren outpu verir.
* */