1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
int strStr(char * haystack, char * needle){ if(strlen(needle) == 0) return 0; if(strlen(haystack) ==0||strlen(haystack) <strlen(needle)) return -1; int x=0,y=0,sta=0; while(x <=strlen(haystack)-strlen(needle)){ if(haystack[x] == needle[y]) sta=1; while(sta){ int a=x+1; while(a-x<strlen(needle)){ y+=1; if(haystack[a] == needle[y]) a++; else{ sta=y=0; break; } } if(sta) return x; } x++; } return -1; }
|