Skip to content

Commit bb7ae0f

Browse files
committed
task 5
1 parent ea9dedf commit bb7ae0f

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

0x07-pointers_arrays_strings/5-strstr.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,24 @@
1010
*/
1111
char *_strstr(char *haystack, char *needle)
1212
{
13-
char *hay;
14-
char *ndl;
13+
char *result = haystack, *fneedle = needle;
1514

16-
while (*haystack != '\0')
15+
while (*haystack)
1716
{
18-
hay = haystack;
19-
ndl = needle;
20-
21-
while (*haystack != '\0' && *ndl != '\0' && *haystack == *ndl)
17+
while (*needle)
18+
{
19+
if (*haystack++ != *needle++)
20+
{
21+
break;
22+
}
23+
}
24+
if (!*needle)
2225
{
23-
haystack++;
24-
ndl++;
26+
return (result);
2527
}
26-
if (!ndl)
27-
return (hay);
28-
haystack = hay + 1;
28+
needle = fneedle;
29+
result++;
30+
haystack = result;
2931
}
3032
return (0);
3133
}

0 commit comments

Comments
 (0)