从给定字符串中寻找子串,如果存在子串,返回子串初始位置

来源:互联网 发布:cms什么意思 编辑:程序博客网 时间:2024/05/16 15:34
/*子串查找*/unsigned int find_str(char *src,char *dst)// 判断dst是否是 src的子串,并返回其在src中的起始位置,不区分大小写{int dstLen=strlen(dst);int count=0;int incount=0;while(*src){if(*src==*dst){src++;dst++;count++;if(count==dstLen){printf("存在子串");printf("下标为:%d",incount);return 1;}}else{src++;incount++;count=0;if(*src=='\0'){printf("不存在子串");return 1;}}}}int main(string args[]){char src[]="abccd";char dst[]="d";find_str(src,dst);}