strstr函数的自己实现
来源:互联网 发布:淘宝拉帮结派帮规 编辑:程序博客网 时间:2024/05/22 04:55
请用标准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()的功能实现
- 网络OSI七层模型
- openssl之aes加密(源码分析 AES_encrypt 与 AES_cbc_encrypt ,加密模式)
- HDOJ还是畅通工程 这阶段唯一自己秒想的题
- WEB架构师成长之路之一-走正确的路(转载)
- android 判断网络状态
- strstr函数的自己实现
- Cygwin的编译错误
- Hibernate validation annonation
- FusionCharts ScrollColumn2D图
- Using C# Yield for Readability and Performance
- 统计出现最多的数字
- 可合并的TREAP
- 写给Python初学者的设计模式入门
- svn常用命令