We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ea9dedf commit bb7ae0fCopy full SHA for bb7ae0f
0x07-pointers_arrays_strings/5-strstr.c
@@ -10,22 +10,24 @@
10
*/
11
char *_strstr(char *haystack, char *needle)
12
{
13
- char *hay;
14
- char *ndl;
+ char *result = haystack, *fneedle = needle;
15
16
- while (*haystack != '\0')
+ while (*haystack)
17
18
- hay = haystack;
19
- ndl = needle;
20
-
21
- while (*haystack != '\0' && *ndl != '\0' && *haystack == *ndl)
+ while (*needle)
+ {
+ if (*haystack++ != *needle++)
+ break;
22
+ }
23
24
+ if (!*needle)
25
- haystack++;
- ndl++;
26
+ return (result);
27
}
- if (!ndl)
- return (hay);
28
- haystack = hay + 1;
+ needle = fneedle;
29
+ result++;
30
+ haystack = result;
31
32
return (0);
33
0 commit comments