maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
ft_strrchr.c
Go to the documentation of this file.
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_strrchr.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: rmikhayl <rmikhayl@student.42london.c +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2023/12/17 17:25:25 by rmikhayl #+# #+# */
9
/* Updated: 2023/12/17 17:25:25 by rmikhayl ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "
libft.h
"
14
15
/* *************************** ft_strrchr *********************************** */
16
/* Searches for the last occurrence of 'c' in the string 's.' */
17
/* Returns a pointer to the found character or NULL if not found. */
18
/* */
19
/* In layman's terms: It's like finding the very last occurrence of a */
20
/* specific character in a sentence. If it's there, you get a pointer to it */
21
/* otherwise, you get nothing. */
22
/* ************************************************************************** */
23
24
char
*
ft_strrchr
(
const
char
*s,
int
c)
25
{
26
unsigned
char
uc;
27
const
char
*last_occurrence;
28
29
last_occurrence = NULL;
30
uc = (
unsigned
char)c;
31
while
(*s !=
'\0'
)
32
{
33
if
(*s == uc)
34
last_occurrence = s;
35
s++;
36
}
37
if
(*s == uc)
38
return
((
char
*)s);
39
return
((
char
*)last_occurrence);
40
}
ft_strrchr
char * ft_strrchr(const char *s, int c)
Definition
ft_strrchr.c:24
libft.h
lib
libft
src
ft_strrchr.c
Generated by
1.9.8