-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strchr.c
57 lines (49 loc) · 1.86 KB
/
ft_strchr.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
54
55
56
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbin-nas <mbin-nas@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 16:08:39 by mbin-nas #+# #+# */
/* Updated: 2022/08/03 14:40:51 by mbin-nas ### ########.fr */
/* */
/* ************************************************************************** */
/*
DESCRIPTION
The strchr() function locates the first occurrence of c
(converted to a char) in
the string pointed to by s.
The terminating null character is considered to be
part of the string; therefore if c is `\0',the functions
locate the terminating \0'.
The strrchr() function is identical to strchr(),
except it locates the last occur-
rence of c.
RETURN VALUES
The functions strchr() and strrchr() return a
pointer to the located character,
or
NULL if the character does not appear in the string.
*/
#include "libft.h"
char *ft_strchr(const char *str, int c)
{
unsigned char ch;
ch = c;
while (*str && (unsigned char)*str != ch)
str++;
if (ch == (unsigned char)*str)
return ((char *)str);
else
return (NULL);
}
// int main()
// {
// const char string[] = "The string is wow";
// int x = 'w';
// const char *p;
// p = ft_strchr(string, x);
// printf("String starting from %c is: %s\n", x, p);
// return (0);
// }