[C Language] implement strstr Functions
# Include <stdio. h> # include <assert. h> char * my_strstr (const char * str1, const char * str2) {assert (str1); assert (str2); char * p = str1; // record the initial position of str1 char * s1 = p; // record the initial position of str1 char * s2 = str2; // record the initial position of str2 while (* p) {s = p; // Add 1 to the start position of str1 from the start position of the previous time, the following p ++ calculates the while (* p & * q & * p = * q) // if it does not match, str2 starts from the first element {p ++; q ++;} if (* q = '\ 0') {return p;} p ++; // mismatch. str1 is backward added by 1} return NULL from the last starting position; // The result is not found after the overall traversal.} int main () {char * str1 = "abbbcdef"; char * str2 = "bbcd"; char * ret = my_strstr (str1, str2); printf ("% s \ n", ret ); return 0 ;}