#2
wangwagn2009-10-28 13:58
|
#include<iostream.h>
#include<string.h>
int parttern_index(char substr[],char str[]);
void main()
{
char *sstr,*mstr;
int index;
sstr="???gram";
mstr="this program return index of substring";
index=parttern_index(sstr,mstr);
if(index!=0)
cout<<"子串起始位置:"<<index<<endl;
else
cout<<"匹配不成功“<<endl;
}
int parttern_index(char substr[],char str[])
{int i,j,k;
for(i=0;str[i];i++)
{
for(j=1,k=0;(str[j]==substr[k])||(substr[k]=='?');j++,k++)
if(!substr[k+1])
return(i);
}
return(0);
}