- 32
- 0
- 约6.7千字
- 约 6页
- 2020-04-19 发布于安徽
- 举报
1. 字符串主串中寻找子串
// 如在 ”acabba”中查找 ”abb ”,若查找到子串,返回子串所在位置,若没有查找到返回 0
int index(char* str , char* T)
{
int i=0,j=0;
int Lenstr,LenT;
Lenstr=strlen(str); //主串长度
Lenstr=strlen(T); //子串长度
while((iLenstr)(jlenT)) // 主串搜索完毕或子串搜索完毕时推出循环
{
if(*(str+i)==*(T+j)) //若当前主串的字符与子串字符相同
{
i++; //主串下移一位
j++; // 子串下移一位
}
else /
原创力文档

文档评论(0)