- 给定一个字符串A,要求在A中查找一个子串B。
如A="ABCDF",要你在A中查找子串B=“CD”。
- char *strstr(const char *strSrc, const char *str)
- {
- assert(strSrc != NULL && str != NULL);
- const char *s = strSrc;
- const char *t = str;
- for (; *strSrc != '\0'; ++ strSrc)
- {
- for (s = strSrc, t = str; *t != '\0' && *s == *t; ++s, ++t)
- NULL;
- if (*t == '\0')
- return (char *) strSrc;
- }
- return NULL;
- }
字串查找
最新推荐文章于 2022-01-12 15:22:23 发布