-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memchr.c
More file actions
51 lines (46 loc) · 1.69 KB
/
ft_memchr.c
File metadata and controls
51 lines (46 loc) · 1.69 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
48
49
50
51
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: simarcha <simarcha@student.42barcelona. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/10 19:22:30 by simarcha #+# #+# */
/* Updated: 2024/09/30 12:08:34 by simarcha ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//look for c in *s within n first characters
//if you have the same string and you are looking for a certain c after the nth
//char, the functions returns (null)
//if *s is NULL, the memchr from the string.h gives us SEGFAULT
//In my case, I protected *s returning (null), if it doesn't exist
void *ft_memchr(const void *s, int c, size_t n)
{
size_t i;
unsigned char *str;
if (!s)
return (NULL);
str = (unsigned char *)s;
i = 0;
while (i < n)
{
if (str[i] == (unsigned char)c)
return (str + i);
i++;
}
return (NULL);
}
/*
#include <string.h>
#include <stdio.h>
int main(void)
{
char *data = NULL;
//char data[14] = "hola que tal?";
//char *pos = memchr(data, 'a', 5);
//printf("Lib : %s\n", pos);
char *pos_sim = ft_memchr(data, 'a', 5);
printf("Sim : %s\n", pos_sim);
return (0);
}*/