-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strchr.c
34 lines (31 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rdragan <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/04 12:27:51 by rdragan #+# #+# */
/* Updated: 2022/11/10 19:40:42 by rdragan ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
Returns the address of the first occurence of c in s.
If c is '\0' then locates it's address in s.
If not found, returns NULL.
To pevent overflow I make sure that is not divisible by 255.
*/
char *ft_strchr(const char *s, int c)
{
int i;
i = -1;
while (s[++i])
{
if (s[i] == (char)c)
return ((char *)s + i);
}
if (s[i] == (char)c)
return ((char *)s + i);
return (NULL);
}