您好,欢迎访问三七文档
#includestdio.h#includestring.h#includestdlib.h#defineOK1#defineERROR0#defineTRUE1#defineFALSE0#defineMAXSIZE40typedefintStatus;typedefcharString[MAXSIZE+1];typedefcharSString;StatusStrAssign(StringT,char*chars);intIndex(SStringS,SStringT,intpos);intmain(void){intpos=1;SStringT,S;T=(char*)malloc(40);S=(char*)malloc(40);char*chars;chars=ababcabcacbab;StrAssign(T,chars);chars=abcac;StrAssign(S,chars);printf(%d,Index(T,S,pos));getchar();return0;}StatusStrAssign(StringT,char*chars){inti;if(strlen(chars)MAXSIZE)returnERROR;else{T[0]=strlen(chars);for(i=1;i=T[0];i++)T[i]=*(chars+i-1);returnOK;}}intIndex(SStringS,SStringT,intpos){inti=pos;intj=1;while(i=S[0]&&j=T[0]){if(S[i]==T[j]){++i;++j;}else{i=i-j+2;j=1;}}if(jT[0])returni-T[0];elsereturn0;}
本文标题:简单匹配模式
链接地址:https://www.777doc.com/doc-2095936 .html