[C语言][面试题][笔试题]模拟实现strstr函数
程序员文章站
2022-11-15 08:31:21
#define _CRT_SECURE_NO_WARNINGS 1
#include
#include
#i...
#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include<assert.h> #include<stdlib.h> char *my_strstr(const char *dst,const char *src) { assert(dst); assert(src); char *p = dst; char *s1 = p; char *s2 = src; while (*s1) { s1 = p; s2 = src; while ((*s1!='\0')&&(*s2 != '\0')) { if (*s1++ == *s2++) { ; } else { p++; break; } } if (*s2 == '\0') { return p; } } } int main() { char *str1 = "abbbcdef"; char *str2 = "bbcd"; char *ret = my_strstr(str1, str2); printf("%s\n", ret); system("pause"); return 0; }
上一篇: 同步pod时区,与node主机保持一致
下一篇: 蒸包子用冷水还是热水,这一步很重要