#include#include const char* mmy_strstr(const char* str1, const char* str2) { assert(str1 != NULL); assert(str2 != NULL); assert(*str1 != ''); assert(*str2 != ''); const char* black = str1; while (*black != '') { const char* red = black; const char* sub = str2; while (*red != '' && *sub != '' && *red == *sub) { red++; sub++; } if (*sub == '') { return black; } black++; } return NULL; } int main() { char str1[1024] = "hello llo llo"; char str2[1024] = "llo"; printf("%c", *mmy_strstr(str1, str2)); return 0; }
实现结果:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)