strstr函数的自己实现
来源:互联网 发布:数据库原理pdf百度云 编辑:程序博客网 时间:2024/06/06 17:19
reference to:
http://blog.csdn.net/wangyangkobe/article/details/6787516
http://baike.baidu.com/view/745156.htm
在计算机内存中,0,'\0',null,是一样的,值也是一样的,都是0。以数字的方式读取就是0,以字符串的方式读取就是'\0',以程序命令或者其他方式读取就是null(null的定义跟编译器有关,有的编译器定义null可能不是0)。
请用标准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);
- if('\0' != *str2)
- {
- while('\0' != *str1)
- {
- for(int index = 0; *(str1 + index) == *(str2 +index); index++)
- {
- if('\0' == *(str2 + index + 1))
- {
- return str1;
- }
- }
- str1++;
- }
- return NULL;
- }
- else
- {
- return str1;
- }
- }
- int main()
- {
- const char *str1 = "wangyang";
- const char *str2[] = {"", "wx", "ang"};
- for(int index = 0; index < 3; index++)
- {
- const char *res = StrStr(str1, str2[index]);
- if(res != NULL)
- cout<<str2[index]<<":Find, start pointer is:"<<res<<endl;
- else
- cout<<str2[index]<<":Not Find"<<endl;
- }
- system("pause");
- }
- 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()的功能实现
- 黑马程序员——HTML和CSS
- TCP/IP - 网络文件系统
- JAVA SWING JTREE
- 递归算法详细分析-> C
- 神经网络编程入门
- strstr函数的自己实现
- 特殊相机
- Android开发搭建(2)
- 生成器模式(Builder)
- js--文档碎片
- 网站的分布式架构
- 【ⓔ传中国研制出世界最快计算机ⓔ每秒狂飙5.49亿亿次ⓔ】
- linux网络编程之socket(九):使用select函数改进客户端/服务器端程序
- android验证底层驱动是否上报正常