// 模拟库函数strstr #include <stdio.h> #include <assert.h> const char* my_strstr(const char *parent, const char *child) { const char *pgo = parent; const char *cgo = child; const char *pgos = parent; assert(parent != NULL && child != NULL); if (!*child) { return NULL; } while (*pgo) { pgo = pgos; cgo = child; while (*pgo == *cgo && *pgo && *cgo) { pgo++; cgo++; } if (*cgo == '\0') return pgos; pgos++; } return NULL; } int main() { printf("%s\n", my_strstr("hhhww", "hhww")); printf("%s\n", my_strstr("zhaoyaqian","aoya")); printf("%s\n", my_strstr("abc", "aefg")); return 0; }
本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5081516.html,如需转载请自行联系原作者