-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strchr.c
More file actions
47 lines (42 loc) · 1.32 KB
/
Copy pathft_strchr.c
File metadata and controls
47 lines (42 loc) · 1.32 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
43
44
45
46
47
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: user <user@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/29 15:30:00 by user #+# #+# */
/* Updated: 2023/04/29 15:30:00 by user ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strchr(const char *s, int c)
{
size_t i;
unsigned char *str;
unsigned char u_c;
if (!s)
return (NULL);
str = (unsigned char *)s;
u_c = (unsigned char)c;
i = 0;
while (str[i])
{
if (str[i] == u_c)
break ;
i++;
}
if (str[i] == u_c)
return ((char *)&str[i]);
return (NULL);
}
int ft_strchr_n(char *s, char c)
{
char *p;
if (!s)
return (-1);
p = ft_strchr(s, c);
if (!p)
return (-1);
return (p - s);
}