[Solved] C – why it’s return me NULL value every-time?


you call ft_strstr("Bonjour", "jour");

ft_strstr calls ft_memcmp("onjour", "jour").

ft_memcmp returns ‘o’ – ‘j’, which is not zero, so

return (!ft_memcmp(++s1, s2, ft_strlen(s2)) ? s1 : NULL); returns NULL

your problem is ft_strstr :

I suppose you wanted to do it recursively ? If it is the case, you forgot the recursion

Here’s an example of a recursive implementation which should work.

char *ft_strstr(char *s1, char const *s2)
{
if (!*s1)
return (NULL);
if (!ft_memcmp(s1, s2, ft_strlen(s2)))
return (s1);
return (ft_strstr(s1 + 1, s2));
}

solved C – why it’s return me NULL value every-time?