I'm trying to build my strstr() function, it's look all fine
but when I execute the code it return nothing ;
This is my function :
#include <stdio.h>
char* ft_strstr(char *str, char *to_find) {
char *a;
char *b;
b = to_find;
if (!*b)
return (char*) str;
while (*str) {
if (*str != *b)
continue;
a = str;
while (1) {
if (!*b)
return (char*) str;
if (*a++ != *b++)
break;
}
str++;
b = to_find;
}
return (NULL);
}
int main() {
char string[] = "Hello from morroco";
char find[] = "from";
ft_strstr(string, find);
printf("%s", find);
return 0;
}
I don't know what. I have to try to fix it cause it looks all fine for me.
return (char *)str;... Ifstralready have the typechar *, there's just no need to do an explicit conversion to the same type.to_findargument. Why shouldfindin themainfunction change? You seem to have some basic misunderstandings about both thestrstrfunction as well as the basics of C.continue;? What situation will you be in when you come toif(*str != *b)again? How is it different from last time you got there?