Skip to content

Instantly share code, notes, and snippets.

@Riketta
Created July 17, 2015 14:09
Show Gist options
  • Save Riketta/a66e735cba8f73f4cbf4 to your computer and use it in GitHub Desktop.
Save Riketta/a66e735cba8f73f4cbf4 to your computer and use it in GitHub Desktop.
int my_strstr(char *haystack, char *needle)
{
int offset = -1;
//for (s = str; *s; ++s);
char *_haystack;
char *_needle = needle; // wtf
for (_haystack = haystack; *_haystack; ++_haystack)
{
if (*_haystack == *_needle)
offset = *_haystack;
if (offset != -1 && *_needle)
{
if (*_haystack != *_needle)
{
*_haystack = offset + 1; // rly?
*_needle = needle;
offset = -1;
}
++_needle;
}
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment