-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strchr.c
More file actions
43 lines (37 loc) · 1.36 KB
/
ft_strchr.c
File metadata and controls
43 lines (37 loc) · 1.36 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ibravo-m <ibravo-m@student.42lisboa.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/19 17:09:34 by ibravo-m #+# #+# */
/* Updated: 2024/05/02 15:20:56 by ibravo-m ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
// finds the first occurrence of c in str and returns str from there
// NULL if it doesnt find
char *ft_strchr(const char *str, int c)
{
int i;
i = 0;
while (str[i])
{
if (str[i] == (char)c)
return ((char *)&str[i]);
i++;
}
if (!((char)c))
return ((char *)&str[i]);
return (NULL);
}
/*int main(void)
{
char str[] = "bom dia";
int c = 'l';
char *test = ft_strchr(str, c);
char *test2 = strchr(str, c);
printf("%s\n", test);
printf("%s\n", test2);
}*/