Created
September 19, 2014 18:34
-
-
Save dermesser/2af65f55c0be32e8fb9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <stdio.h> | |
# include <stdlib.h> | |
# include <string.h> | |
# include <stdbool.h> | |
_Bool find(const char* haystack, const char* needle) | |
{ | |
size_t hlen = strlen(haystack); | |
size_t nlen = strlen(needle); | |
unsigned int found = 0; | |
for ( unsigned int i = 0; i < hlen; i++ ) | |
{ | |
found = 0; | |
for ( unsigned int j = 0; i+j < hlen; j++ ) | |
{ | |
if ( haystack[i+j] != needle[j] ) | |
break; | |
else | |
found++; | |
} | |
if ( found == nlen ) | |
break; | |
} | |
if ( found == nlen ) | |
return true; | |
else | |
return false; | |
} | |
int main(void) | |
{ | |
printf("%i\n",find("abcdefg","efgh")); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment