-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
34 lines (30 loc) · 1.4 KB
/
ft_strnstr.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_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: inwagner <inwagner@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/03 18:11:11 by inwagner #+# #+# */
/* Updated: 2023/06/09 18:39:32 by inwagner ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t n)
{
size_t littlen;
if (!*little)
return ((char *)big);
littlen = ft_strlen(little);
while (*big && littlen <= n--)
{
if (!ft_strncmp(big, little, littlen))
return ((char *)big);
big++;
}
return (0);
}
/*
Procura a primeira ocorrência da string `little` na string `big` até `len` bytes.
Retorna `big` se `little` for uma string vazia, retorna nulo se não achar `little` dentro de `big`, retorna a posição de `big` onde `little` se inicia.
*/