strstr函数的自己实现
来源:互联网 发布:类似于知乎的网站 编辑:程序博客网 时间:2024/06/02 16:27
请用标准C语言实现下列标准库函数,设计中不得使用其他库函数。
char *strstr(char *str1,char *str2);
在字符串str1中,寻找字串str2,若找到返回找到的位置,否则返回NULL。
- #include <iostream>
- #include <cassert>
- using namespace std;
- const char* StrStr(const char *str1, const char *str2)
- {
- assert(NULL != str1 && NULL != str2);
- while(*str1 != '\0')
- {
- const char *p = str1;
- const char *q = str2;
- const char *res = NULL;
- if(*p == *q)
- {
- res = p;
- while(*p && *q && *p++ == *q++)
- ;
- if(*q == '\0')
- return res;
- }
- str1++;
- }
- return NULL;
- }
- int main()
- {
- const char *str1 = "wangyang";
- const char *str2 = "ang";
- const char *res = StrStr(str1, str2);
- if(res != NULL)
- cout<<res<<endl;
- else
- cout<<"NOT"<<endl;
- system("pause");
- }
0 0
- strstr函数的自己实现
- strstr函数的自己实现
- strstr函数的自己实现
- 实现自己的strstr函数
- strstr函数的自己实现
- 自己实现strstr函数
- strstr函数 自己实现
- strstr函数的实现
- strstr 函数的 实现
- strstr函数的实现
- strstr 函数的实现
- strstr函数的实现
- 自己实现strstr函数与strchr函数
- c/c++自己实现strstr函数
- c++ strstr函数的实现
- strstr函数的简单实现
- strstr()函数的实现
- 【LeetCode】005 Implement strStr() 函数strStr()的功能实现
- 每天工作计划
- [C++11 并发编程] 14 关联任务与期望
- JSONUtils 工具类
- AOJ 2534 Dictionary
- 学习JS(7)
- strstr函数的自己实现
- 6天通吃树结构—— 第五天 Trie树
- 复制DataTable时出现"该行已经属于另一个表"异常的解决办法
- 网站搭建过程中后台相关 随笔
- 求果园中在t*s的矩阵里最多能有几棵柿子树 二维树状数组模板题 poj 2029 Get Many Persimmon Trees
- 移动端购物车的实现
- 数字处理类
- 谢尔排序
- leetcode 214: Shortest Palindrome