首页 > 其他 > 详细

字符串中子串的查找

时间:2015-07-31 18:19:44      阅读:226      评论:0      收藏:0      [点我收藏+]

字符串中子串的查找

// 字符串中子串的查找.cpp : 定义控制台应用程序的入口点。
//

// 字符串中子串的查找.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<stdio.h>
#include<assert.h>
#include<windows.h>
const char *strstr(const char* src,const char* sub)
{
    const char* bp;
    const char* sp;

    if(src==NULL||NULL==sub)//判断src与sub的有效性
        {
        return src;
        }
    while(*src)//遍历src字符串
        {
        bp=src;
        sp=sub;
        do
        {
            if(!*sp)
                return src;
        }while(*bp++==*sub++);
        src+=1;
        }
    return NULL;
}
int main()
{
    char p[]="12345";
    char q[]="34";
    const char *r= strstr(p,q);
    printf("r: %s\n",r);
    system("pause");
    return 0;
}

技术分享

版权声明:本文为博主原创文章,未经博主允许不得转载。

字符串中子串的查找

原文:http://blog.csdn.net/u011233535/article/details/47173331

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!