用指针实现字符串匹配(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