strstr函数的实现
来源:互联网 发布:淘宝食品店需要什么 编辑:程序博客网 时间:2024/05/19 00:08
函数要求:使用标准C语言实现下列标准库函数,设计中不得使用其他库函数。
函数原型:char *strstr(char *str1,char *str2);
说明:在字符串str1中,寻找字串str2,若找到返回找到的位置,否则返回NULL。
实现代码如下:
函数原型:char *strstr(char *str1,char *str2);
说明:在字符串str1中,寻找字串str2,若找到返回找到的位置,否则返回NULL。
实现代码如下:
- #include <stdio.h>
- #include <errno.h>
- #include <assert.h>
- char *strstr(const char *find,const char *need);
- int main()
- {
- const char buf1[100] = "heelor";
- const char buf2[100] = "lor";
-
- const char *res =strstr(buf1,buf2);
- printf("the res=%s",res);
- return 0;
- }
- char *strstr(const char *find, const char *need)
- {
- assert(find !=NULL && need !=NULL);
- while( *find !='\0')
- {
- const char *p=find;
- const char *q =need;
- const char *res= NULL;
- if(*p == *q)
- {
- res= p;
- while(*p++ == *q++)
- ;
- if(*q == '\0')
- return res;
-
- }
- find ++;
- }
- return NULL;
- }
1 0
- strstr函数的实现
- strstr 函数的 实现
- strstr函数的实现
- strstr 函数的实现
- strstr函数的实现
- strstr函数的自己实现
- strstr函数的自己实现
- c++ strstr函数的实现
- strstr函数的简单实现
- strstr函数的自己实现
- strstr()函数的实现
- 实现自己的strstr函数
- strstr函数的自己实现
- 【LeetCode】005 Implement strStr() 函数strStr()的功能实现
- 编写实现strstr()函数功能的代码
- 类似strstr/strcpy/strpbrk函数的实现
- strstr和memcmp函数的实现
- C 函数 strstr 的高效实现
- iOS学习笔记15- 直接拿来用!最火的iOS开源项目(一)
- 表单域规范写法
- 链地址处理哈希冲突方法
- Java学习博客地址
- POJ 3740 Easy Finding (DLX模板)
- strstr函数的实现
- fax T30 T38协议二进制分析
- 解决listCtrl 无法显示列头的问题
- 打印字符串中重复的字符
- activiti5.17使用自定义的user和group表的几种方法
- java中substring的用法
- 黑马程序员_java基础之IO流(二)
- iOS学习笔记16-直接拿来用!最火的iOS开源项目(二)
- 7Reverse Integer