#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int BFindex(char *src,char *T)
{
int i=0;
int index=0;
int j=0;
char *s =src;
if (strlen(src) <0 ||strlen(T)<0||strlen(src)>strlen(T))
return -1;
while(*s !='\0' && *T !='\0')
{
if (*T==*s)
{
j++;//相等字符的个数
s++;
}
else
{
s=src;
T= T -j ;//重置目标串的位置。
#include <string.h>
#include <stdlib.h>
int BFindex(char *src,char *T)
{
int i=0;
int index=0;
int j=0;
char *s =src;
if (strlen(src) <0 ||strlen(T)<0||strlen(src)>strlen(T))
return -1;
while(*s !='\0' && *T !='\0')
{
if (*T==*s)
{
j++;//相等字符的个数
s++;
}
else
{
s=src;
T= T -j ;//重置目标串的位置。
j=0;
}
T++;
i++;//总共循环的次数
}
if (*s=='\0' )
{
printf("i===%d,j===%d\n",i,j);
return i-j+1;//返回下标值
}
}
int main(int argc,char *argv[])
{
int index=-1;
if (argc!=3)
{
printf("input src,dst\n");
return -1;
}
index =BFindex(argv[1],argv[2]);
printf("string %s in %s from %d start\n",argv[1],argv[2],index);
}