用指针实现字符串匹配(strstr)

void mystrstr(char *sub,char *str){
    int i;
    if(*sub){
        while(*str){
            for(i=0;*(str+i)==*(sub+i);i++){
                if(!*(sub+i+1))
                    printf("%s\n","match");
            }   
            str++;
        }   
    }else{
        printf("%s\n","match");
    }   
}

void main(){
    char *sub="abc";
    char *str="abababc";
    mystrstr(sub,str);
}

参考:https://blog.csdn.net/smf0504/article/details/51372073

 

posted @ 2018-04-19 15:24  Hsinwang  阅读(295)  评论(0编辑  收藏  举报