correction memcpy pour le cas ou dst et src sont nuls
This commit is contained in:
42
srcs/ft_strnstr.c
Normal file
42
srcs/ft_strnstr.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:58:10 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:58:11 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** locate the first occurence of the string little in len first characters
|
||||
** of big and return a pointer to this occurence if found
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
j = 0;
|
||||
i = 0;
|
||||
if (!ft_strlen(little))
|
||||
return ((char *)big);
|
||||
while (i == 0 && j <= len)
|
||||
{
|
||||
while (little[i] == big[j + i] && little[i] && j + i <= len)
|
||||
i++;
|
||||
if (little[i])
|
||||
{
|
||||
j++;
|
||||
if (!big[j] || j >= len)
|
||||
return (0);
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
return ((char *)big + j);
|
||||
}
|
||||
Reference in New Issue
Block a user