-
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.5 KB
/
ft_strrchr.c
File metadata and controls
42 lines (38 loc) · 1.5 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: ccarnot <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/05 12:48:47 by ccarnot #+# #+# */
/* Updated: 2023/05/11 18:30:07 by ccarnot ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*******************************************
* Function: strrchr
* Library: <string.h>
* Description: searches for the first occurrence of a specific character in a string * Memory allocations: None
* Crash values:
* - s is NULL (unprotected)
* Return value:
* - pointer to the first occurrence of the character in the string
* - NULL if the character is not found
*******************************************/
char *ft_strrchr(const char *s, int c)
{
int i;
char ch;
i = 0;
ch = c;
while (s[i])
i++;
while (i >= 0)
{
if (s[i] == ch)
return ((char *)s + i);
i--;
}
return (0x0);
}