strstr库函数实现

#include<stdio.h>
#include<assert.h>

char *strstr(char* src,char *sub)
{
    if(src==NULL||NULL==sub)
    {
        return src;
    }
    
    const char *bp=src;
    const char *sp=sub;
    
    while(*src)
    {
        bp=src;
        sp=sub;
        do{
            if(!*sp)
                return src;
            }while(*bp++==*sp++);
        src+=1;
    }
    
    return NULL;
}

int main()
{
    char p[]="12345";
    char q[]="134";
    char *r=strstr(p,q);
    printf("r:%s\n",r);
    
    return 0;
}

 

posted @ 2017-01-10 18:01  邹大佳  阅读(3147)  评论(0编辑  收藏  举报