-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strchr.c
55 lines (47 loc) · 1.62 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcosta-d <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/17 19:40:26 by mcosta-d #+# #+# */
/* Updated: 2023/04/23 18:58:29 by mcosta-d ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strchr(const char *str, int c)
{
int i;
i = 0;
while (str[i])
{
if ((unsigned char)str[i] == (unsigned char)c)
return ((char *)&str[i]);
i++;
}
if ((unsigned char)str[i] == (unsigned char)c)
return ((char *)&str[i]);
return (NULL);
}
/*
#include <stdio.h>
#include<string.h>
int main()
{
const char str[] = "Hello, world!";
char *result = ft_strchr(str, '\0');
char *result2 = strchr(str, '\0');
if (result == NULL)
{
printf("Character not found in mine\n");
}
if (result2 == NULL)
printf("Character not found in original\n");
else
{
printf("Mine: char found at pos: %ld\n", result - str);
printf("Org: char found at pos: %ld\n", result2 - str);
}
return 0;
}*/