C strstr函数代码实现

int  * Mystrstr(const char * str1, const char* str2)
{
    char*  p1 = NULL;
    char * p2 = NULL;
    char * cur = (char *)str1;

    if (*p2=='\0')
    {
        return cur;
    }
    while (*cur)
    {
        p1 = cur;
        p2 = (char *)str2;

        while ((*p1!='\0')&& (*p2 != '\0') &&(*p1==*p2) )
        {
            p1++;
            p2++;
        }
        if (*p2 == '\0')
        {
            return cur;
        }

        cur++;
    }
    return NULL;
}

 

posted @ 2021-04-12 18:39  紅人  阅读(114)  评论(0编辑  收藏  举报