#include
#include
void find_substr(char s[],int slen,char t[],int tlen)
{
int i,j;
i = j = 0;
while(i < slen && j < tlen)
if(s[i] == t[j])
{
i++;
j++;
}else
{
i = i-j+1;
j = 0;
}
if(j == tlen)
printf("%d\n",i-tlen);
else
printf("can not found!\n");
}
int main(int argc, char *argv[])
{
char s[25] = {"hello,what is your name!"};
char t[10] = {"your"};
int slen,tlen,i,j;
slen = strlen(s);
tlen = strlen(t);
for(i = 0; i < slen; i++)
printf("%c",s[i]);
printf("\n");
for(i = 0; i < tlen; i++)
printf("%c",t[i]);
printf("\n");
find_substr(s,slen,t,tlen);
return 0;
}
阅读(832) | 评论(0) | 转发(0) |