-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memchr.c
46 lines (41 loc) · 1.49 KB
/
ft_memchr.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dpaluszk <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/08 16:27:14 by dpaluszk #+# #+# */
/* Updated: 2024/03/18 16:17:02 by dpaluszk ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
size_t i;
unsigned char *str;
str = (unsigned char *)s;
i = 0;
while (i < n)
{
if ((unsigned char)str[i] == (unsigned char)c)
return ((unsigned char *)&s[i]);
i++;
}
return (NULL);
}
// int main()
// {
// char *word = "truskawka";
// int d = 'w';
// char *result = ft_memchr(word, d, 10);
// if (result != NULL)
// {
//printf ("Character '%c' found at position: %ld\n", *result, result - word);
// }
// else
// {
// printf("Character '%c' not found in the string.\n", d);
// }
// return 0;
// }